home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cc / dist / reload1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-06  |  106.6 KB  |  3,293 lines

  1. /* Reload pseudo regs into hard regs for insns that require hard regs.
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include "config.h"
  22. #include "rtl.h"
  23. #include "insn-config.h"
  24. #include "flags.h"
  25. #include "regs.h"
  26. #include "hard-reg-set.h"
  27. #include "reload.h"
  28. #include "recog.h"
  29. #include "basic-block.h"
  30. #include <stdio.h>
  31.  
  32. #define min(A,B) ((A) < (B) ? (A) : (B))
  33. #define max(A,B) ((A) > (B) ? (A) : (B))
  34.  
  35. /* This file contains the reload pass of the compiler, which is
  36.    run after register allocation has been done.  It checks that
  37.    each insn is valid (operands required to be in registers really
  38.    are in registers of the proper class) and fixes up invalid ones
  39.    by copying values temporarily into registers for the insns
  40.    that need them.
  41.  
  42.    The results of register allocation are described by the vector
  43.    reg_renumber; the insns still contain pseudo regs, but reg_renumber
  44.    can be used to find which hard reg, if any, a pseudo reg is in.
  45.  
  46.    The technique we always use is to free up a few hard regs that are
  47.    called ``reload regs'', and for each place where a pseudo reg
  48.    must be in a hard reg, copy it temporarily into one of the reload regs.
  49.  
  50.    All the pseudos that were formerly allocated to the hard regs that
  51.    are now in use as reload regs must be ``spilled''.  This means
  52.    that they go to other hard regs, or to stack slots if no other
  53.    available hard regs can be found.  Spilling can invalidate more
  54.    insns, requiring additional need for reloads, so we must keep checking
  55.    until the process stabilizes.
  56.  
  57.    For machines with different classes of registers, we must keep track
  58.    of the register class needed for each reload, and make sure that
  59.    we allocate enough reload registers of each class.
  60.  
  61.    The file reload.c contains the code that checks one insn for
  62.    validity and reports the reloads that it needs.  This file
  63.    is in charge of scanning the entire rtl code, accumulating the
  64.    reload needs, spilling, assigning reload registers to use for
  65.    fixing up each insn, and generating the new insns to copy values
  66.    into the reload registers.  */
  67.  
  68. /* During reload_as_needed, element N contains a REG rtx for the hard reg
  69.    into which pseudo reg N has been reloaded (perhaps for a previous insn). */
  70. static rtx *reg_last_reload_reg;
  71.  
  72. /* Elt N nonzero if reg_last_reload_reg[N] has been set in this insn
  73.    for an output reload that stores into reg N.  */
  74. static char *reg_has_output_reload;
  75.  
  76. /* Elt N nonzero if hard reg N is a reload-register for an output reload
  77.    in the current insn.  */
  78. static char reg_is_output_reload[FIRST_PSEUDO_REGISTER];
  79.  
  80. /* Element N is the constant value to which pseudo reg N is equivalent,
  81.    or zero if pseudo reg N is not equivalent to a constant.
  82.    find_reloads looks at this in order to replace pseudo reg N
  83.    with the constant it stands for.  */
  84. rtx *reg_equiv_constant;
  85.  
  86. /* Element N is the address of stack slot to which pseudo reg N is equivalent.
  87.    This is used when the address is not valid as a memory address
  88.    (because its displacement is too big for the machine.)  */
  89. rtx *reg_equiv_address;
  90.  
  91. /* Element N is the memory slot to which pseudo reg N is equivalent,
  92.    or zero if pseudo reg N is not equivalent to a memory slot.  */
  93. rtx *reg_equiv_mem;
  94.  
  95. /* Widest width in which each pseudo reg is referred to (via subreg).  */
  96. static int *reg_max_ref_width;
  97.  
  98. /* Element N is the insn that initialized reg N from its equivalent
  99.    constant or memory slot.  */
  100. static rtx *reg_equiv_init;
  101.  
  102. /* During reload_as_needed, element N contains the last pseudo regno
  103.    reloaded into the Nth reload register.  This vector is in parallel
  104.    with spill_regs.  */
  105. static int reg_reloaded_contents[FIRST_PSEUDO_REGISTER];
  106.  
  107. /* Number of spill-regs so far; number of valid elements of spill_regs.  */
  108. static int n_spills;
  109.  
  110. /* In parallel with spill_regs, contains REG rtx's for those regs.
  111.    Holds the last rtx used for any given reg, or 0 if it has never
  112.    been used for spilling yet.  This rtx is reused, provided it has
  113.    the proper mode.  */
  114. static rtx spill_reg_rtx[FIRST_PSEUDO_REGISTER];
  115.  
  116. /* In parallel with spill_regs, contains nonzero for a spill reg
  117.    that was stored after the last time it was used.
  118.    The precise value is the insn generated to do the store.  */
  119. static rtx spill_reg_store[FIRST_PSEUDO_REGISTER];
  120.  
  121. /* This table is the inverse mapping of spill_regs:
  122.    indexed by hard reg number,
  123.    it contains the position of that reg in spill_regs,
  124.    or -1 for something that is not in spill_regs.  */
  125. static short spill_reg_order[FIRST_PSEUDO_REGISTER];
  126.  
  127. /* This table contains 1 for a register that may not be used
  128.    for retrying global allocation, or -1 for a register that may be used.
  129.    The registers that may not be used include all spill registers
  130.    and the frame pointer (if we are using one).  */
  131. static short forbidden_regs[FIRST_PSEUDO_REGISTER];
  132.  
  133. /* Describes order of use of registers for reloading
  134.    of spilled pseudo-registers.  `spills' is the number of
  135.    elements that are actually valid; new ones are added at the end.  */
  136. static char spill_regs[FIRST_PSEUDO_REGISTER];
  137.  
  138. /* Describes order of preference for putting regs into spill_regs.
  139.    Contains the numbers of all the hard regs, in order most preferred first.
  140.    This order is different for each function.
  141.    It is set up by order_regs_for_reload.
  142.    Empty elements at the end contain -1.  */
  143. static short potential_reload_regs[FIRST_PSEUDO_REGISTER];
  144.  
  145. /* 1 for a hard register that appears explicitly in the rtl
  146.    (for example, function value registers, special registers
  147.    used by insns, structure value pointer registers).  */
  148. static char regs_explicitly_used[FIRST_PSEUDO_REGISTER];
  149.  
  150. /* For each register, 1 if it was counted against the need for
  151.    groups.  0 means it can count against max_nongroup instead.  */
  152. static char counted_for_groups[FIRST_PSEUDO_REGISTER];
  153.  
  154. /* For each register, 1 if it was counted against the need for
  155.    non-groups.  0 means it can become part of a new group.
  156.    During choose_reload_regs, 1 here means don't use this reg
  157.    as part of a group, even if it seems to be otherwise ok.  */
  158. static char counted_for_nongroups[FIRST_PSEUDO_REGISTER];
  159.  
  160. /* Nonzero if spilling (REG n) does not require reloading it into
  161.    a register in order to do (MEM (REG n)).  */
  162.  
  163. static char spill_indirect_ok;
  164.  
  165. /* Nonzero if an address (plus (reg frame_pointer) (reg ...)) is valid.  */
  166.  
  167. char double_reg_address_ok;
  168.  
  169. /* Record the stack slot for each spilled hard register.  */
  170.  
  171. static rtx spill_stack_slot[FIRST_PSEUDO_REGISTER];
  172.  
  173. /* Width allocated so far for that stack slot.  */
  174.  
  175. static int spill_stack_slot_width[FIRST_PSEUDO_REGISTER];
  176.  
  177. /* Indexed by basic block number, nonzero if there is any need
  178.    for a spill register in that basic block.
  179.    The pointer is 0 if we did stupid allocation and don't know
  180.    the structure of basic blocks.  */
  181.  
  182. char *basic_block_needs;
  183.  
  184. /* First uid used by insns created by reload in this function.
  185.    Used in find_equiv_reg.  */
  186. int reload_first_uid;
  187.  
  188. /* Flag set by local-alloc or global-alloc if anything is live in
  189.    a call-clobbered reg across calls.  */
  190.  
  191. int caller_save_needed;
  192.  
  193. /* Set to 1 by alter_frame_pointer_addresses if it changes anything.  */
  194.  
  195. static int frame_pointer_address_altered;
  196.  
  197. void mark_home_live ();
  198. static rtx scan_paradoxical_subregs ();
  199. static void reload_as_needed ();
  200. static int modes_equiv_for_class_p ();
  201. static rtx alter_frame_pointer_addresses ();
  202. static void alter_reg ();
  203. static int new_spill_reg();
  204. static int spill_hard_reg ();
  205. static void choose_reload_regs ();
  206. static void emit_reload_insns ();
  207. static void delete_output_reload ();
  208. static void forget_old_reloads_1 ();
  209. static void order_regs_for_reload ();
  210. static void eliminate_frame_pointer ();
  211. static rtx inc_for_reload ();
  212. static int constraint_accepts_reg_p ();
  213. static int count_occurrences ();
  214. static rtx gen_input_reload ();
  215.  
  216. extern void remove_death ();
  217. extern rtx adj_offsettable_operand ();
  218.  
  219. /* Main entry point for the reload pass, and only entry point
  220.    in this file.
  221.  
  222.    FIRST is the first insn of the function being compiled.
  223.  
  224.    GLOBAL nonzero means we were called from global_alloc
  225.    and should attempt to reallocate any pseudoregs that we
  226.    displace from hard regs we will use for reloads.
  227.    If GLOBAL is zero, we do not have enough information to do that,
  228.    so any pseudo reg that is spilled must go to the stack.
  229.  
  230.    DUMPFILE is the global-reg debugging dump file stream, or 0.
  231.    If it is nonzero, messages are written to it to describe
  232.    which registers are seized as reload regs, which pseudo regs
  233.    are spilled from them, and where the pseudo regs are reallocated to.  */
  234.  
  235. void
  236. reload (first, global, dumpfile)
  237.      rtx first;
  238.      int global;
  239.      FILE *dumpfile;
  240. {
  241.   register int class;
  242.   register int i;
  243.   register rtx insn;
  244.  
  245.   int something_changed;
  246.   int something_needs_reloads;
  247.   int new_basic_block_needs;
  248.  
  249.   /* The basic block number currently being processed for INSN.  */
  250.   int this_block;
  251.  
  252.   /* Often (MEM (REG n)) is still valid even if (REG n) is put on the stack.
  253.      Set spill_indirect_ok if so.  */
  254.   register rtx tem
  255.     = gen_rtx (MEM, Pmode,
  256.            gen_rtx (PLUS, Pmode,
  257.             gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM),
  258.             gen_rtx (CONST_INT, VOIDmode, 4)));
  259.  
  260.   spill_indirect_ok = memory_address_p (QImode, tem);
  261.  
  262.   tem = gen_rtx (PLUS, Pmode, 
  263.          gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM),
  264.          gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM));
  265.   /* This way, we make sure that reg+reg is an offsettable address.  */
  266.   tem = plus_constant (tem, 4);
  267.  
  268.   double_reg_address_ok = memory_address_p (QImode, tem);
  269.  
  270.   /* Enable find_equiv_reg to distinguish insns made by reload.  */
  271.   reload_first_uid = get_max_uid ();
  272.  
  273.   basic_block_needs = 0;
  274.  
  275.   /* Remember which hard regs appear explicitly
  276.      before we merge into `regs_ever_live' the ones in which
  277.      pseudo regs have been allocated.  */
  278.   bcopy (regs_ever_live, regs_explicitly_used, sizeof regs_ever_live);
  279.  
  280.   /* We don't have a stack slot for any spill reg yet.  */
  281.   bzero (spill_stack_slot, sizeof spill_stack_slot);
  282.   bzero (spill_stack_slot_width, sizeof spill_stack_slot_width);
  283.  
  284.   /* Compute which hard registers are now in use
  285.      as homes for pseudo registers.
  286.      This is done here rather than (eg) in global_alloc
  287.      because this point is reached even if not optimizing.  */
  288.  
  289.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  290.     mark_home_live (i);
  291.  
  292.   /* Make sure that the last insn in the chain
  293.      is not something that needs reloading.  */
  294.   emit_note (0, NOTE_INSN_DELETED);
  295.  
  296.   /* Find all the pseudo registers that didn't get hard regs
  297.      but do have known equivalent constants or memory slots.
  298.      These include parameters (known equivalent to parameter slots)
  299.      and cse'd or loop-moved constant memory addresses.
  300.  
  301.      Record constant equivalents in reg_equiv_constant
  302.      so they will be substituted by find_reloads.
  303.      Record memory equivalents in reg_mem_equiv so they can
  304.      be substituted eventually by altering the REG-rtx's.  */
  305.  
  306.   reg_equiv_constant = (rtx *) alloca (max_regno * sizeof (rtx));
  307.   bzero (reg_equiv_constant, max_regno * sizeof (rtx));
  308.   reg_equiv_mem = (rtx *) alloca (max_regno * sizeof (rtx));
  309.   bzero (reg_equiv_mem, max_regno * sizeof (rtx));
  310.   reg_equiv_init = (rtx *) alloca (max_regno * sizeof (rtx));
  311.   bzero (reg_equiv_init, max_regno * sizeof (rtx));
  312.   reg_equiv_address = (rtx *) alloca (max_regno * sizeof (rtx));
  313.   bzero (reg_equiv_address, max_regno * sizeof (rtx));
  314.   reg_max_ref_width = (int *) alloca (max_regno * sizeof (int));
  315.   bzero (reg_max_ref_width, max_regno * sizeof (int));
  316.  
  317.   /* Look for REG_EQUIV notes; record what each pseudo is equivalent to.
  318.      Also find all paradoxical subregs
  319.      and find largest such for each pseudo.  */
  320.  
  321.   for (insn = first; insn; insn = NEXT_INSN (insn))
  322.     {
  323.       if (GET_CODE (insn) == INSN
  324.       && GET_CODE (PATTERN (insn)) == SET
  325.       && GET_CODE (SET_DEST (PATTERN (insn))) == REG)
  326.     {
  327.       rtx note = find_reg_note (insn, REG_EQUIV, 0);
  328.       if (note)
  329.         {
  330.           rtx x = XEXP (note, 0);
  331.           i = REGNO (SET_DEST (PATTERN (insn)));
  332.           if (i >= FIRST_PSEUDO_REGISTER)
  333.         {
  334.           if (GET_CODE (x) == MEM)
  335.             {
  336.               if (memory_address_p (GET_MODE (x), XEXP (x, 0)))
  337.             reg_equiv_mem[i] = x;
  338.               else
  339.             reg_equiv_address[i] = XEXP (x, 0);
  340.             }
  341.           else if (immediate_operand (x, VOIDmode))
  342.             reg_equiv_constant[i] = x;
  343.           else
  344.             continue;
  345.           reg_equiv_init[i] = insn;
  346.         }
  347.         }
  348.     }
  349.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  350.       || GET_CODE (insn) == JUMP_INSN)
  351.     scan_paradoxical_subregs (PATTERN (insn));
  352.     }
  353.  
  354.   /* Does this function require a frame pointer?  */
  355.  
  356.   frame_pointer_needed
  357.     |= (! global || FRAME_POINTER_REQUIRED);
  358.  
  359.   if (! frame_pointer_needed)
  360.     frame_pointer_needed
  361.       = check_frame_pointer_required (reg_equiv_constant,
  362.                       reg_equiv_mem, reg_equiv_address);
  363.  
  364.   /* Alter each pseudo-reg rtx to contain its hard reg number.
  365.      Delete initializations of pseudos that don't have hard regs
  366.      and do have equivalents.
  367.      Assign stack slots to the pseudos that lack hard regs or equivalents.  */
  368.  
  369.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  370.     alter_reg (i, -1);
  371.  
  372. #ifndef REGISTER_CONSTRAINTS
  373.   /* If all the pseudo regs have hard regs,
  374.      except for those that are never referenced,
  375.      we know that no reloads are needed.  */
  376.   /* But that is not true if there are register constraints, since
  377.      in that case some pseudos might be in the wrong kind of hard reg.  */
  378.  
  379.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  380.     if (reg_renumber[i] == -1 && reg_n_refs[i] != 0)
  381.       break;
  382.  
  383.   if (i == max_regno && frame_pointer_needed && ! caller_save_needed)
  384.     return;
  385. #endif
  386.  
  387.   /* Compute the order of preference for hard registers to spill.
  388.      Store them by decreasing preference in potential_reload_regs.  */
  389.  
  390.   order_regs_for_reload ();
  391.  
  392.   /* So far, no hard regs have been spilled.  */
  393.   n_spills = 0;
  394.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  395.     {
  396.       spill_reg_order[i] = -1;
  397.       forbidden_regs[i] = -1;
  398.     }
  399.  
  400.   if (caller_save_needed)
  401.     frame_pointer_needed = 1;
  402.  
  403.   if (frame_pointer_needed)
  404.     {
  405.       forbidden_regs[FRAME_POINTER_REGNUM] = 1;
  406.       spill_hard_reg (FRAME_POINTER_REGNUM, global, dumpfile);
  407.     }
  408.  
  409.   if (global)
  410.     {
  411.       basic_block_needs = (char *)alloca (n_basic_blocks);
  412.       bzero (basic_block_needs, n_basic_blocks);
  413.     }
  414.  
  415.   /* This loop scans the entire function each go-round
  416.      and repeats until one repetition spills no additional hard regs.  */
  417.  
  418.   /* This flag is set when a psuedo reg is spilled,
  419.      to require another pass.  Note that getting an additional reload
  420.      reg does not necessarily imply any pseudo reg was spilled;
  421.      sometimes we find a reload reg that no pseudo reg was allocated in.  */
  422.   something_changed = 1;
  423.   /* This flag is set if there are any insns that require reloading.  */
  424.   something_needs_reloads = 0;
  425.   while (something_changed)
  426.     {
  427.       /* For each class, number of reload regs needed in that class.
  428.      This is the maximum over all insns of the needs in that class
  429.      of the individual insn.  */
  430.       int max_needs[N_REG_CLASSES];
  431.       /* For each class, size of group of consecutive regs
  432.      that is needed for the reloads of this class.  */
  433.       int group_size[N_REG_CLASSES];
  434.       /* For each class, max number of consecutive groups needed.
  435.      (Each group contains max_needs_size[CLASS] consecutive registers.)  */
  436.       int max_groups[N_REG_CLASSES];
  437.       /* For each class, max number needed of regs that don't belong
  438.      to any of the groups.  */
  439.       int max_nongroups[N_REG_CLASSES];
  440.       /* For each class, the machine mode which requires consecutive
  441.      groups of regs of that class.
  442.      If two different modes ever require groups of one class,
  443.      they must be the same size and equally restrictive for that class,
  444.      otherwise we can't handle the complexity.  */
  445.       enum machine_mode group_mode[N_REG_CLASSES];
  446.  
  447.       something_changed = 0;
  448.       bzero (max_needs, sizeof max_needs);
  449.       bzero (max_groups, sizeof max_groups);
  450.       bzero (max_nongroups, sizeof max_nongroups);
  451.       bzero (group_size, sizeof group_size);
  452.       for (i = 0; i < N_REG_CLASSES; i++)
  453.     group_mode[i] = VOIDmode;
  454.  
  455.       /* Keep track of which basic blocks are needing the reloads.  */
  456.       this_block = 0;
  457.  
  458.       /* Remember whether any element of basic_block_needs
  459.      changes from 0 to 1 in this pass.  */
  460.       new_basic_block_needs = 0;
  461.  
  462.       /* Compute the most additional registers needed by any instruction.
  463.      Collect information separately for each class of regs.  */
  464.  
  465.       for (insn = first; insn; insn = NEXT_INSN (insn))
  466.     {
  467.       if (global && this_block + 1 < n_basic_blocks
  468.           && insn == basic_block_head[this_block+1])
  469.         ++this_block;
  470.  
  471.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  472.           || GET_CODE (insn) == CALL_INSN)
  473.         {
  474.           /* Initially, count RELOAD_OTHER reloads.
  475.          Later, merge in the other kinds.  */
  476.           int insn_needs[N_REG_CLASSES];
  477.           int insn_groups[N_REG_CLASSES];
  478.           int insn_total_groups = 0;
  479.  
  480.           /* Count RELOAD_FOR_INPUT_RELOAD_ADDRESS reloads.  */
  481.           int insn_needs_for_inputs[N_REG_CLASSES];
  482.           int insn_groups_for_inputs[N_REG_CLASSES];
  483.           int insn_total_groups_for_inputs = 0;
  484.  
  485.           /* Count RELOAD_FOR_OUTPUT_RELOAD_ADDRESS reloads.  */
  486.           int insn_needs_for_outputs[N_REG_CLASSES];
  487.           int insn_groups_for_outputs[N_REG_CLASSES];
  488.           int insn_total_groups_for_outputs = 0;
  489.  
  490.           /* Count RELOAD_FOR_OPERAND_ADDRESS reloads.  */
  491.           int insn_needs_for_operands[N_REG_CLASSES];
  492.           int insn_groups_for_operands[N_REG_CLASSES];
  493.           int insn_total_groups_for_operands = 0;
  494.  
  495.           for (i = 0; i < N_REG_CLASSES; i++)
  496.         {
  497.           insn_needs[i] = 0, insn_groups[i] = 0;
  498.           insn_needs_for_inputs[i] = 0, insn_groups_for_inputs[i] = 0;
  499.           insn_needs_for_outputs[i] = 0, insn_groups_for_outputs[i] = 0;
  500.           insn_needs_for_operands[i] = 0, insn_groups_for_operands[i] = 0;
  501.         }
  502.  
  503. #if 0  /* This wouldn't work nowadays, since optimize_bit_field
  504.       looks for non-strict memory addresses.  */
  505.           /* Optimization: a bit-field instruction whose field
  506.          happens to be a byte or halfword in memory
  507.          can be changed to a move instruction.  */
  508.  
  509.           if (GET_CODE (PATTERN (insn)) == SET)
  510.         {
  511.           rtx dest = SET_DEST (PATTERN (insn));
  512.           rtx src = SET_SRC (PATTERN (insn));
  513.  
  514.           if (GET_CODE (dest) == ZERO_EXTRACT
  515.               || GET_CODE (dest) == SIGN_EXTRACT)
  516.             optimize_bit_field (PATTERN (insn), insn, reg_equiv_mem);
  517.           if (GET_CODE (src) == ZERO_EXTRACT
  518.               || GET_CODE (src) == SIGN_EXTRACT)
  519.             optimize_bit_field (PATTERN (insn), insn, reg_equiv_mem);
  520.         }
  521. #endif
  522.  
  523.           /* Analyze the instruction.  */
  524.  
  525.           find_reloads (insn, 0, spill_indirect_ok, global, spill_reg_order);
  526.  
  527.           if (n_reloads == 0)
  528.         continue;
  529.  
  530.           something_needs_reloads = 1;
  531.  
  532.           /* Count each reload once in every class
  533.          containing the reload's own class.  */
  534.  
  535.           for (i = 0; i < n_reloads; i++)
  536.         {
  537.           register enum reg_class *p;
  538.           int size;
  539.           enum machine_mode mode;
  540.           int *this_groups;
  541.           int *this_needs;
  542.           int *this_total_groups;
  543.  
  544.           /* Don't use dummy reloads in regs
  545.              being spilled in this block.  */
  546.           if (reload_reg_rtx[i] != 0
  547.               && (!global || basic_block_needs[this_block])
  548.               && spill_reg_order[REGNO (reload_reg_rtx[i])] >= 0)
  549.             reload_reg_rtx[i] = 0;
  550.  
  551.           /* Don't count the dummy reloads, for which one of the
  552.              regs mentioned in the insn can be used for reloading.
  553.              Don't count optional reloads.
  554.              Don't count reloads that got combined with others.  */
  555.           if (reload_reg_rtx[i] != 0
  556.               || reload_optional[i] != 0
  557.               || (reload_out[i] == 0 && reload_in[i] == 0))
  558.             continue;
  559.  
  560.           /* Decide which time-of-use to count this reload for.  */
  561.           switch (reload_when_needed[i])
  562.             {
  563.             case RELOAD_OTHER:
  564.               this_needs = insn_needs;
  565.               this_groups = insn_groups;
  566.               this_total_groups = &insn_total_groups;
  567.               break;
  568.  
  569.             case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  570.               this_needs = insn_needs_for_inputs;
  571.               this_groups = insn_groups_for_inputs;
  572.               this_total_groups = &insn_total_groups_for_inputs;
  573.               break;
  574.  
  575.             case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  576.               this_needs = insn_needs_for_outputs;
  577.               this_groups = insn_groups_for_outputs;
  578.               this_total_groups = &insn_total_groups_for_outputs;
  579.               break;
  580.  
  581.             case RELOAD_FOR_OPERAND_ADDRESS:
  582.               this_needs = insn_needs_for_operands;
  583.               this_groups = insn_groups_for_operands;
  584.               this_total_groups = &insn_total_groups_for_operands;
  585.               break;
  586.             }
  587.  
  588.           mode = reload_inmode[i];
  589.           if (GET_MODE_SIZE (reload_outmode[i]) > GET_MODE_SIZE (mode))
  590.             mode = reload_outmode[i];
  591.           size = CLASS_MAX_NREGS (reload_reg_class[i], mode);
  592.           if (size > 1)
  593.             {
  594.               /* Count number of groups needed separately from
  595.              number of individual regs needed.  */
  596.               this_groups[(int) reload_reg_class[i]]++;
  597.               p = reg_class_superclasses[(int) reload_reg_class[i]];
  598.               while (*p != LIM_REG_CLASSES)
  599.             this_groups[(int) *p++]++;
  600.               (*this_total_groups)++;
  601.  
  602.               /* If a group of consecutive regs are needed,
  603.              record which machine mode needs them.
  604.              Crash if two dissimilar machine modes both need
  605.              groups of consecutive regs of the same class.  */
  606.  
  607.               if (group_mode[(int) reload_reg_class[i]] != VOIDmode
  608.               &&
  609.               (! modes_equiv_for_class_p (group_mode[(int) reload_reg_class[i]], mode, reload_reg_class[i])
  610.                ||
  611.                group_size[(int) reload_reg_class[i]] != size))
  612.             abort ();
  613.  
  614.               /* Record size and mode of a group of this class.  */
  615.               group_size[(int) reload_reg_class[i]] = size;
  616.               group_mode[(int) reload_reg_class[i]] = mode;
  617.             }
  618.           else if (size == 1)
  619.             {
  620.               this_needs[(int) reload_reg_class[i]] += 1;
  621.               p = reg_class_superclasses[(int) reload_reg_class[i]];
  622.               while (*p != LIM_REG_CLASSES)
  623.             this_needs[(int) *p++] += 1;
  624.             }
  625.           else
  626.             abort ();
  627.  
  628.           if (global)
  629.             {
  630.               if (! basic_block_needs[this_block])
  631.             new_basic_block_needs = 1;
  632.               basic_block_needs[this_block] = 1;
  633.             }
  634.         }
  635.  
  636.           /* All reloads have been counted for this insn;
  637.          now merge the various times of use.
  638.          This sets insn_needs, etc., to the maximum total number
  639.          of registers needed at any point in this insn.  */
  640.  
  641.           for (i = 0; i < N_REG_CLASSES; i++)
  642.         {
  643.           int this_max;
  644.           this_max = insn_needs_for_inputs[i];
  645.           if (insn_needs_for_outputs[i] > this_max)
  646.             this_max = insn_needs_for_outputs[i];
  647.           if (insn_needs_for_operands[i] > this_max)
  648.             this_max = insn_needs_for_operands[i];
  649.           insn_needs[i] += this_max;
  650.           this_max = insn_groups_for_inputs[i];
  651.           if (insn_groups_for_outputs[i] > this_max)
  652.             this_max = insn_groups_for_outputs[i];
  653.           if (insn_groups_for_operands[i] > this_max)
  654.             this_max = insn_groups_for_operands[i];
  655.           insn_groups[i] += this_max;
  656.         }
  657.           insn_total_groups += max (insn_total_groups_for_inputs,
  658.                     max (insn_total_groups_for_outputs,
  659.                          insn_total_groups_for_operands));
  660.  
  661.           /* Remember for later shortcuts which insns had any reloads.  */
  662.  
  663.           PUT_MODE (insn, n_reloads ? QImode : VOIDmode);
  664.  
  665.           /* For each class, collect maximum need of any insn.  */
  666.  
  667.           for (i = 0; i < N_REG_CLASSES; i++)
  668.         {
  669.           if (max_needs[i] < insn_needs[i])
  670.             max_needs[i] = insn_needs[i];
  671.           if (max_groups[i] < insn_groups[i])
  672.             max_groups[i] = insn_groups[i];
  673.           if (insn_total_groups > 0)
  674.             if (max_nongroups[i] < insn_needs[i])
  675.               max_nongroups[i] = insn_needs[i];
  676.         }
  677.         }
  678.       /* Note that there is a continue statement above.  */
  679.     }
  680.  
  681.       /* Now deduct from the needs for the registers already
  682.      available (already spilled).  */
  683.  
  684.       bzero (counted_for_groups, sizeof counted_for_groups);
  685.       bzero (counted_for_nongroups, sizeof counted_for_nongroups);
  686.  
  687.       /* Find all consecutive groups of spilled registers
  688.      and mark each group off against the need for such groups.  */
  689.  
  690.       for (i = 0; i < N_REG_CLASSES; i++)
  691.     if (group_size[i] > 1)
  692.       {
  693.         char regmask[FIRST_PSEUDO_REGISTER];
  694.         int j;
  695.  
  696.         bzero (regmask, sizeof regmask);
  697.         /* Make a mask of all the regs that are spill regs in class I.  */
  698.         for (j = 0; j < n_spills; j++)
  699.           if (TEST_HARD_REG_BIT (reg_class_contents[i], spill_regs[j])
  700.           && !counted_for_groups[spill_regs[j]])
  701.         regmask[spill_regs[j]] = 1;
  702.         /* Find each consecutive group of them.  */
  703.         for (j = 0; j < FIRST_PSEUDO_REGISTER && max_groups[i] > 0; j++)
  704.           if (regmask[j] && j + group_size[i] <= FIRST_PSEUDO_REGISTER
  705.           /* Next line in case group-mode for this class
  706.              demands an even-odd pair.  */
  707.           && HARD_REGNO_MODE_OK (j, group_mode[i]))
  708.         {
  709.           int k;
  710.           for (k = 1; k < group_size[i]; k++)
  711.             if (! regmask[j + k])
  712.               break;
  713.           if (k == group_size[i])
  714.             {
  715.               /* We found a group.  Mark it off against this class's
  716.              need for groups, and against each superclass too.  */
  717.               register enum reg_class *p;
  718.               max_groups[i]--;
  719.               p = reg_class_superclasses[i];
  720.               while (*p != LIM_REG_CLASSES)
  721.             max_groups[(int) *p++]--;
  722.               /* Don't count these registers again.  */ 
  723.               counted_for_groups[j] = 1;
  724.               for (k = 1; k < group_size[i]; k++)
  725.             counted_for_groups[j + k] = 1;
  726.             }
  727.           j += k;
  728.         }
  729.       }
  730.  
  731.       /* Now count all remaining spill regs against the individual need.
  732.      Those that weren't counted_for_groups in groups can also count against
  733.      the not-in-group need.  */
  734.  
  735.       for (i = 0; i < n_spills; i++)
  736.     {
  737.       register enum reg_class *p;
  738.       class = (int) REGNO_REG_CLASS (spill_regs[i]);
  739.  
  740.       max_needs[class]--;
  741.       p = reg_class_superclasses[class];
  742.       while (*p != LIM_REG_CLASSES)
  743.         max_needs[(int) *p++]--;
  744.  
  745.       if (! counted_for_groups[spill_regs[i]])
  746.         {
  747.           if (max_nongroups[class] > 0)
  748.         counted_for_nongroups[spill_regs[i]] = 1;
  749.           max_nongroups[class]--;
  750.           p = reg_class_superclasses[class];
  751.           while (*p != LIM_REG_CLASSES)
  752.         {
  753.           if (max_nongroups[(int) *p] > 0)
  754.             counted_for_nongroups[spill_regs[i]] = 1;
  755.           max_nongroups[(int) *p++]--;
  756.         }
  757.         }
  758.     }
  759.  
  760.       /* If all needs are met, we win.  */
  761.  
  762.       for (i = 0; i < N_REG_CLASSES; i++)
  763.     if (max_needs[i] > 0 || max_groups[i] > 0 || max_nongroups[i] > 0)
  764.       break;
  765.       if (i == N_REG_CLASSES && !new_basic_block_needs)
  766.     break;
  767.  
  768.       /* Not all needs are met; must spill more hard regs.  */
  769.  
  770.       /* If any element of basic_block_needs changed from 0 to 1,
  771.      re-spill all the regs already spilled.  This may spill
  772.      additional pseudos that didn't spill before.  */
  773.  
  774.       if (new_basic_block_needs)
  775.     for (i = 0; i < n_spills; i++)
  776.       something_changed
  777.         |= spill_hard_reg (spill_regs[i], global, dumpfile);
  778.  
  779.       /* Now find more reload regs to satisfy the remaining need
  780.      Do it by ascending class number, since otherwise a reg
  781.      might be spilled for a big class and might fail to count
  782.      for a smaller class even though it belongs to that class.
  783.  
  784.      Count spilled regs in `spills', and add entries to
  785.      `spill_regs' and `spill_reg_order'.  */
  786.  
  787.       for (class = 0; class < N_REG_CLASSES; class++)
  788.     {
  789.       /* First get the groups of registers.
  790.          If we got single registers first, we might fragment
  791.          possible groups.  */
  792.       while (max_groups[class] > 0)
  793.         {
  794.           /* Groups of size 2 (the only groups used on most machines)
  795.          are treated specially.  */
  796.           if (group_size[class] == 2)
  797.         {
  798.           /* First, look for a register that will complete a group.  */
  799.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  800.             {
  801.               int j = potential_reload_regs[i];
  802.               int other;
  803.               if (j >= 0 && !fixed_regs[j]
  804.               &&
  805.               ((j > 0 && (other = j - 1, spill_reg_order[other] >= 0)
  806.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  807.                 && TEST_HARD_REG_BIT (reg_class_contents[class], other)
  808.                 && HARD_REGNO_MODE_OK (other, group_mode[class])
  809.                 && ! counted_for_nongroups[other]
  810.                 /* We don't want one part of another group.
  811.                    We could get "two groups" that overlap!  */
  812.                 && ! counted_for_groups[other])
  813.  
  814.                ||
  815.                (j < FIRST_PSEUDO_REGISTER - 1
  816.                 && (other = j + 1, spill_reg_order[other] >= 0)
  817.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  818.                 && TEST_HARD_REG_BIT (reg_class_contents[class], other)
  819.                 && HARD_REGNO_MODE_OK (j, group_mode[class])
  820.                 && ! counted_for_nongroups[other]
  821.                 && ! counted_for_groups[other])))
  822.             {
  823.               register enum reg_class *p;
  824.  
  825.               /* We have found one that will complete a group,
  826.                  so count off one group as provided.  */
  827.               max_groups[class]--;
  828.               p = reg_class_superclasses[class];
  829.               while (*p != LIM_REG_CLASSES)
  830.                 max_groups[(int) *p++]--;
  831.  
  832.               /* Indicate both these regs are part of a group.  */
  833.               counted_for_groups[j] = 1;
  834.               counted_for_groups[other] = 1;
  835.  
  836.               break;
  837.             }
  838.             }
  839.           /* We can't complete a group, so start one.  */
  840.           if (i == FIRST_PSEUDO_REGISTER)
  841.             for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  842.               {
  843.             int j = potential_reload_regs[i];
  844.             if (j >= 0 && j + 1 < FIRST_PSEUDO_REGISTER
  845.                 && spill_reg_order[j] < 0 && spill_reg_order[j + 1] < 0
  846.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  847.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j + 1)
  848.                 && HARD_REGNO_MODE_OK (j, group_mode[class])
  849.                 && ! counted_for_nongroups[j + 1])
  850.               break;
  851.               }
  852.  
  853.           /* I should be the index in potential_reload_regs
  854.              of the new reload reg we have found.  */
  855.  
  856.           something_changed
  857.             |= new_spill_reg (i, class, max_needs, 0,
  858.                       global, dumpfile);
  859.         }
  860.           else
  861.         {
  862.           /* For groups of more than 2 registers,
  863.              look for a sufficient sequence of unspilled registers,
  864.              and spill them all at once.  */
  865.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  866.             {
  867.               int j = potential_reload_regs[i];
  868.               int k;
  869.               if (j >= 0 && j + 1 < FIRST_PSEUDO_REGISTER
  870.               && HARD_REGNO_MODE_OK (j, group_mode[class]))
  871.             {
  872.               /* Check each reg in the sequence.  */
  873.               for (k = 0; k < group_size[class]; k++)
  874.                 if (! (spill_reg_order[j + k] < 0
  875.                    && !fixed_regs[j + k]
  876.                    && TEST_HARD_REG_BIT (reg_class_contents[class], j + k)))
  877.                   break;
  878.               /* We got a full sequence, so spill them all.  */
  879.               if (k == group_size[class])
  880.                 {
  881.                   register enum reg_class *p;
  882.                   for (k = 0; k < group_size[class]; k++)
  883.                 {
  884.                   int idx;
  885.                   counted_for_groups[j + k] = 1;
  886.                   for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx++)
  887.                     if (potential_reload_regs[idx] == j + k)
  888.                       break;
  889.                   something_changed
  890.                     |= new_spill_reg (idx, class, max_needs, 0,
  891.                               global, dumpfile);
  892.                 }
  893.  
  894.                   /* We have found one that will complete a group,
  895.                  so count off one group as provided.  */
  896.                   max_groups[class]--;
  897.                   p = reg_class_superclasses[class];
  898.                   while (*p != LIM_REG_CLASSES)
  899.                 max_groups[(int) *p++]--;
  900.  
  901.                   break;
  902.                 }
  903.             }
  904.             }
  905.         }
  906.         }
  907.  
  908.       /* Now similarly satisfy all need for single registers.  */
  909.  
  910.       while (max_needs[class] > 0 || max_nongroups[class] > 0)
  911.         {
  912.           /* Consider the potential reload regs that aren't
  913.          yet in use as reload regs, in order of preference.
  914.          Find the most preferred one that's in this class.  */
  915.  
  916.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  917.         if (potential_reload_regs[i] >= 0
  918.             && TEST_HARD_REG_BIT (reg_class_contents[class],
  919.                       potential_reload_regs[i]))
  920.           break;
  921.  
  922.           /* I should be the index in potential_reload_regs
  923.          of the new reload reg we have found.  */
  924.  
  925.           something_changed
  926.         |= new_spill_reg (i, class, max_needs, max_nongroups,
  927.                   global, dumpfile);
  928.         }
  929.     }
  930.     }
  931.  
  932.   /* Insert code to save and restore call-clobbered hard regs
  933.      around calls.  */
  934.  
  935.   if (caller_save_needed)
  936.     save_call_clobbered_regs ();
  937.  
  938.   /* Now we know for certain whether we have a frame pointer.
  939.      If not, correct all references to go through the stack pointer.
  940.      This must be done before reloading, since reloading could generate
  941.      insns where sp+const cannot validly replace the frame pointer.
  942.      *This will lose if an insn might need more spill regs after
  943.      frame pointer elimination than it needed before.*  */
  944.  
  945.   if (! frame_pointer_needed)
  946.     eliminate_frame_pointer (first);
  947.  
  948.   /* Use the reload registers where necessary
  949.      by generating move instructions to move the must-be-register
  950.      values into or out of the reload registers.  */
  951.  
  952.   if (something_needs_reloads)
  953.     reload_as_needed (first, global);
  954.  
  955.   /* Now eliminate all pseudo regs by modifying them into
  956.      their equivalent memory references.
  957.      The REG-rtx's for the pseudos are modified in place,
  958.      so all insns that used to refer to them now refer to memory.
  959.  
  960.      For a reg that has a reg_equiv_address, all those insns
  961.      were changed by reloading so that no insns refer to it any longer;
  962.      but the DECL_RTL of a variable decl may refer to it,
  963.      and if so this causes the debugging info to mention the variable.  */
  964.  
  965.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  966.     {
  967.       rtx addr = 0;
  968.       if (reg_equiv_mem[i])
  969.     addr = XEXP (reg_equiv_mem[i], 0);
  970.       if (reg_equiv_address[i])
  971.     addr = reg_equiv_address[i];
  972.       if (addr)
  973.     {
  974.       if (! frame_pointer_needed)
  975.         FIX_FRAME_POINTER_ADDRESS (addr, 0);
  976.       if (reg_renumber[i] < 0)
  977.         {
  978.           rtx reg = regno_reg_rtx[i];
  979.           XEXP (reg, 0) = addr;
  980.           REG_USERVAR_P (reg) = 0;
  981.           PUT_CODE (reg, MEM);
  982.         }
  983.       else if (reg_equiv_mem[i])
  984.         XEXP (reg_equiv_mem[i], 0) = addr;
  985.     }
  986.     }
  987. }
  988.  
  989. /* 1 if two machine modes MODE0 and MODE1 are equivalent
  990.    as far as HARD_REGNO_MODE_OK is concerned
  991.    for registers in class CLASS.  */
  992.  
  993. static int
  994. modes_equiv_for_class_p (mode0, mode1, class)
  995.      enum machine_mode mode0, mode1;
  996.      enum reg_class class;
  997. {
  998.   register int regno;
  999.   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
  1000.     {
  1001.       /* If any reg in CLASS allows one mode but not the other, fail.
  1002.      Or if the two modes have different sizes in that reg, fail.  */
  1003.       if (TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno)
  1004.       && (HARD_REGNO_MODE_OK (regno, mode0)
  1005.           != HARD_REGNO_MODE_OK (regno, mode1))
  1006.       && (HARD_REGNO_NREGS (regno, mode0)
  1007.           != HARD_REGNO_NREGS (regno, mode1)))
  1008.     return 0;
  1009.     }
  1010.   return 1;
  1011. }
  1012.  
  1013. /* Add a new register to the tables of available spill-registers
  1014.     (as well as spilling all pseudos allocated to the register).
  1015.    I is the index of this register in potential_reload_regs.
  1016.    CLASS is the regclass whose need is being satisfied.
  1017.    MAX_NEEDS and MAX_NONGROUPS are the vectors of needs,
  1018.     so that this register can count off against them.
  1019.     MAX_NONGROUPS is 0 if this register is part of a group.
  1020.    GLOBAL and DUMPFILE are the same as the args that `reload' got.  */
  1021.  
  1022. static int
  1023. new_spill_reg (i, class, max_needs, max_nongroups, global, dumpfile)
  1024.      int i;
  1025.      int class;
  1026.      int *max_needs;
  1027.      int *max_nongroups;
  1028.      int global;
  1029.      FILE *dumpfile;
  1030. {
  1031.   register enum reg_class *p;
  1032.   int val;
  1033.   int regno = potential_reload_regs[i];
  1034.  
  1035.   if (i >= FIRST_PSEUDO_REGISTER)
  1036.     abort ();    /* Caller failed to find any register.  */
  1037.  
  1038.   /* Make reg REGNO an additional reload reg.  */
  1039.  
  1040.   potential_reload_regs[i] = -1;
  1041.   spill_regs[n_spills] = regno;
  1042.   spill_reg_order[regno] = n_spills;
  1043.   forbidden_regs[regno] = 1;
  1044.   if (dumpfile)
  1045.     fprintf (dumpfile, "Spilling reg %d.\n", spill_regs[n_spills]);
  1046.  
  1047.   /* Clear off the needs we just satisfied.  */
  1048.  
  1049.   max_needs[class]--;
  1050.   p = reg_class_superclasses[class];
  1051.   while (*p != LIM_REG_CLASSES)
  1052.     max_needs[(int) *p++]--;
  1053.  
  1054.   if (max_nongroups && max_nongroups[class] > 0)
  1055.     {
  1056.       counted_for_nongroups[regno] = 1;
  1057.       max_nongroups[class]--;
  1058.       p = reg_class_superclasses[class];
  1059.       while (*p != LIM_REG_CLASSES)
  1060.     max_nongroups[(int) *p++]--;
  1061.     }
  1062.  
  1063.   /* Spill every pseudo reg that was allocated to this reg
  1064.      or to something that overlaps this reg.  */
  1065.  
  1066.   val = spill_hard_reg (spill_regs[n_spills], global, dumpfile);
  1067.  
  1068.   regs_ever_live[spill_regs[n_spills]] = 1;
  1069.   n_spills++;
  1070.  
  1071.   return val;
  1072. }
  1073.  
  1074. /* Scan all insns, computing the stack depth, and convert all
  1075.    frame-pointer-relative references to stack-pointer-relative references.  */
  1076.  
  1077. static void
  1078. eliminate_frame_pointer (first)
  1079.      rtx first;
  1080. {
  1081.   int depth = 0;
  1082.   int max_uid = get_max_uid ();
  1083.   int *label_depth = (int *) alloca ((max_uid + 1) * sizeof (int));
  1084.   int i;
  1085.   rtx insn;
  1086.  
  1087.   for (i = 0; i <= max_uid; i++)
  1088.     label_depth[i] = -1;
  1089.  
  1090.   /* In this loop, for each forward branch we record the stack
  1091.      depth of the label it jumps to.  We take advantage of the fact
  1092.      that the stack depth at a label reached by a backward branch
  1093.      is always, in GCC output, equal to the stack depth of the preceding
  1094.      unconditional jump, because it was either a loop statement or
  1095.      statement label.  */
  1096.  
  1097.   for (insn = first; insn; insn = NEXT_INSN (insn))
  1098.     {
  1099.       rtx pattern = PATTERN (insn);
  1100.       switch (GET_CODE (insn))
  1101.     {
  1102.     case INSN:
  1103.       frame_pointer_address_altered = 0;
  1104.       alter_frame_pointer_addresses (pattern, depth);
  1105.       /* Rerecognize insn if changed.  */
  1106.       if (frame_pointer_address_altered)
  1107.         INSN_CODE (insn) = -1;
  1108.  
  1109.       /* Notice pushes and pops; update DEPTH.  */
  1110.       if (GET_CODE (pattern) == SET)
  1111.         {
  1112. #ifdef PUSH_ROUNDING
  1113.           if (push_operand (SET_DEST (pattern),
  1114.                 GET_MODE (SET_DEST (pattern))))
  1115.         depth += PUSH_ROUNDING (GET_MODE_SIZE (GET_MODE (SET_DEST (pattern))));
  1116. #endif
  1117.           if (GET_CODE (SET_DEST (pattern)) == REG
  1118.           && REGNO (SET_DEST (pattern)) == STACK_POINTER_REGNUM)
  1119.         {
  1120.           int delta;
  1121.           if (GET_CODE (SET_SRC (pattern)) == PLUS
  1122.               && GET_CODE (XEXP (SET_SRC (pattern), 0)) == REG
  1123.               && REGNO (XEXP (SET_SRC (pattern), 0)) == STACK_POINTER_REGNUM)
  1124.             delta = INTVAL (XEXP (SET_SRC (pattern), 1));
  1125.           else if (GET_CODE (SET_SRC (pattern)) == MINUS
  1126.                && GET_CODE (XEXP (SET_SRC (pattern), 0)) == REG
  1127.                && REGNO (XEXP (SET_SRC (pattern), 0)) == STACK_POINTER_REGNUM)
  1128.             delta = -INTVAL (XEXP (SET_SRC (pattern), 1));
  1129.           else abort ();
  1130. #ifdef STACK_GROWS_DOWNWARD
  1131.           depth -= delta;
  1132. #else
  1133.           depth += delta;
  1134. #endif
  1135.         }
  1136.         }
  1137.       break;
  1138.  
  1139.     case JUMP_INSN:
  1140.       frame_pointer_address_altered = 0;
  1141.       alter_frame_pointer_addresses (pattern, depth);
  1142.       /* Rerecognize insn if changed.  */
  1143.       if (frame_pointer_address_altered)
  1144.         INSN_CODE (insn) = -1;
  1145.  
  1146.       if (GET_CODE (pattern) == ADDR_VEC)
  1147.         for (i = 0; i < XVECLEN (pattern, 0); i++)
  1148.           label_depth[INSN_UID (XEXP (XVECEXP (pattern, 0, i), 0))] = depth;
  1149.       else if (GET_CODE (pattern) == ADDR_DIFF_VEC)
  1150.         {
  1151.           label_depth[INSN_UID (XEXP (XEXP (pattern, 0), 0))] = depth;
  1152.           for (i = 0; i < XVECLEN (pattern, 1); i++)
  1153.         label_depth[INSN_UID (XEXP (XVECEXP (pattern, 1, i), 0))] = depth;
  1154.         }
  1155.       else if (JUMP_LABEL (insn))
  1156.         label_depth[INSN_UID (JUMP_LABEL (insn))] = depth;
  1157.       else
  1158.       break;
  1159.  
  1160.     case CODE_LABEL:
  1161.       if (label_depth [INSN_UID (insn)] >= 0)
  1162.         depth = label_depth [INSN_UID (insn)];
  1163.       break;
  1164.  
  1165.     case CALL_INSN:
  1166.       frame_pointer_address_altered = 0;
  1167.       alter_frame_pointer_addresses (pattern, depth);
  1168.       /* Rerecognize insn if changed.  */
  1169.       if (frame_pointer_address_altered)
  1170.         INSN_CODE (insn) = -1;
  1171.       break;
  1172.     }
  1173.     }
  1174. }
  1175.  
  1176. /* Walk the rtx X, converting all frame-pointer refs to stack-pointer refs
  1177.    on the assumption that the current temporary stack depth is DEPTH.
  1178.    (The size of saved registers must be added to DEPTH
  1179.    to get the actual offset between the logical frame-pointer and the
  1180.    stack pointer.  FIX_FRAME_POINTER_ADDRESS takes care of that.)  */
  1181.  
  1182. static rtx
  1183. alter_frame_pointer_addresses (x, depth)
  1184.      register rtx x;
  1185.      int depth;
  1186. {
  1187.   register int i;
  1188.   register char *fmt;
  1189.   register enum rtx_code code = GET_CODE (x);
  1190.  
  1191.   switch (code)
  1192.     {
  1193.     case CONST_INT:
  1194.     case CONST:
  1195.     case SYMBOL_REF:
  1196.     case LABEL_REF:
  1197.     case CONST_DOUBLE:
  1198.     case CC0:
  1199.     case PC:
  1200.       return x;
  1201.  
  1202.     case REG:
  1203.       /* Frame ptr can occur outside a PLUS if a stack slot
  1204.      can occur with offset 0.  */
  1205.       if (x == frame_pointer_rtx)
  1206.     {
  1207.       rtx oldx = x;
  1208.       FIX_FRAME_POINTER_ADDRESS (x, depth);
  1209.       if (x != oldx)
  1210.         frame_pointer_address_altered = 1;
  1211.     }
  1212.       return x;
  1213.  
  1214.     case MEM:
  1215.       {
  1216.     rtx addr = XEXP (x, 0);
  1217.     rtx mem;
  1218.     rtx old_addr = addr;
  1219.     FIX_FRAME_POINTER_ADDRESS (addr, depth);
  1220.     if (addr != old_addr)
  1221.       frame_pointer_address_altered = 1;
  1222.     /* These MEMs are normally shared.  Make a changed copy;
  1223.        don't alter the shared MEM, since it needs to be altered
  1224.        differently each time it occurs (since DEPTH varies).  */
  1225.     mem = gen_rtx (MEM, GET_MODE (x), addr);
  1226.     MEM_VOLATILE_P (mem) = MEM_VOLATILE_P (x);
  1227.     return mem;
  1228.       }
  1229.  
  1230.     case PLUS:
  1231.       {
  1232.     rtx oldx = x;
  1233.     /* Handle addresses being loaded or pushed, etc.,
  1234.        rather than referenced.  */
  1235.     FIX_FRAME_POINTER_ADDRESS (x, depth);
  1236.     if (x != oldx)
  1237.       frame_pointer_address_altered = 1;
  1238.     code = GET_CODE (x);
  1239.     break;
  1240.       }
  1241.     }
  1242.  
  1243.   fmt = GET_RTX_FORMAT (code);
  1244.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1245.     {
  1246.       if (fmt[i] == 'e')
  1247.     XEXP (x, i) = alter_frame_pointer_addresses (XEXP (x, i), depth);
  1248.       else if (fmt[i] == 'E')
  1249.     {
  1250.       register int j;
  1251.       for (j = XVECLEN (x, i) - 1; j >=0; j--)
  1252.         XVECEXP (x, i, j)
  1253.           = alter_frame_pointer_addresses (XVECEXP (x, i, j), depth);
  1254.     }
  1255.     }
  1256.   return x;
  1257. }
  1258.  
  1259. /* Modify the home of pseudo-reg I.
  1260.    The new home is present in reg_renumber[I].
  1261.  
  1262.    FROM_REG may be the hard reg that the pseudo-reg is being spilled from;
  1263.    or it may be -1, meaning there is none or it is not relevant.
  1264.    This is used so that all pseudos spilled from a given hard reg
  1265.    can share one stack slot.  */
  1266.  
  1267. static void
  1268. alter_reg (i, from_reg)
  1269.      register int i;
  1270.      int from_reg;
  1271. {
  1272.   /* When outputting an inline function, this can happen
  1273.      for a reg that isn't actually used.  */
  1274.   if (regno_reg_rtx[i] == 0)
  1275.     return;
  1276.  
  1277.   /* If the reg got changed to a MEM at rtl-generation time,
  1278.      ignore it.  */
  1279.   if (GET_CODE (regno_reg_rtx[i]) != REG)
  1280.     return;
  1281.  
  1282.   /* Modify the reg-rtx to contain the new hard reg
  1283.      number or else to contain its pseudo reg number.  */
  1284.   REGNO (regno_reg_rtx[i])
  1285.     = reg_renumber[i] >= 0 ? reg_renumber[i] : i;
  1286.  
  1287.   if (reg_renumber[i] < 0 && reg_equiv_init[i])
  1288.     {
  1289.       /* Delete the insn that loads the pseudo register.  */
  1290.       PUT_CODE (reg_equiv_init[i], NOTE);
  1291.       NOTE_LINE_NUMBER (reg_equiv_init[i])
  1292.     = NOTE_INSN_DELETED;
  1293.       NOTE_SOURCE_FILE (reg_equiv_init[i]) = 0;
  1294.     }
  1295.  
  1296.   /* If we have a pseudo that is needed but has no hard reg or equivalent,
  1297.      allocate a stack slot for it.  */
  1298.  
  1299.   if (reg_renumber[i] < 0
  1300.       && reg_n_refs[i] > 0
  1301.       && reg_equiv_constant[i] == 0
  1302.       && reg_equiv_mem[i] == 0
  1303.       && reg_equiv_address[i] == 0)
  1304.     {
  1305.       register rtx x, addr;
  1306.       int inherent_size = PSEUDO_REGNO_BYTES (i);
  1307.       int total_size = max (inherent_size, reg_max_ref_width[i]);
  1308.  
  1309.       /* Each pseudo reg has an inherent size which comes from its own mode,
  1310.      and a total size which provides room for paradoxical subregs
  1311.      which refer to the pseudo reg in wider modes.
  1312.  
  1313.      We can use a slot already allocated if it provides both
  1314.      enough inherent space and enough total space.
  1315.      Otherwise, we allocate a new slot, making sure that it has no less
  1316.      inherent space, and no less total space, then the previous slot.  */
  1317.       if (from_reg == -1)
  1318.     {
  1319.       /* No known place to spill from => no slot to reuse.  */
  1320.       x = assign_stack_local (GET_MODE (regno_reg_rtx[i]), total_size);
  1321. #ifdef BYTES_BIG_ENDIAN
  1322.       /* Cancel the  big-endian correction done in assign_stack_local.
  1323.          Get the address of the beginning of the slot.
  1324.          This is so we can do a big-endian correction unconditionally
  1325.          below.  */
  1326.       x = gen_rtx (MEM, GET_MODE (regno_reg_rtx[i]),
  1327.                plus_constant (XEXP (x, 0),
  1328.                       inherent_size - total_size));
  1329. #endif
  1330.     }
  1331.       /* Reuse a stack slot if possible.  */
  1332.       else if (spill_stack_slot[from_reg] != 0
  1333.            && spill_stack_slot_width[from_reg] >= total_size
  1334.            && (GET_MODE_SIZE (GET_MODE (spill_stack_slot[from_reg]))
  1335.            >= inherent_size))
  1336.     x = spill_stack_slot[from_reg];
  1337.       /* Allocate a new or bigger slot.  */
  1338.       else
  1339.     {
  1340.       /* Compute maximum size needed, both for inherent size
  1341.          and for total size.  */
  1342.       enum machine_mode mode = GET_MODE (regno_reg_rtx[i]);
  1343.       if (spill_stack_slot[from_reg])
  1344.         {
  1345.           if (GET_MODE_SIZE (GET_MODE (spill_stack_slot[from_reg]))
  1346.           > inherent_size)
  1347.         mode = GET_MODE (spill_stack_slot[from_reg]);
  1348.           if (spill_stack_slot_width[from_reg] > total_size)
  1349.         total_size = spill_stack_slot_width[from_reg];
  1350.         }
  1351.       /* Make a slot with that size.  */
  1352.       x = assign_stack_local (mode, total_size);
  1353. #ifdef BYTES_BIG_ENDIAN
  1354.       /* Cancel the  big-endian correction done in assign_stack_local.
  1355.          Get the address of the beginning of the slot.
  1356.          This is so we can do a big-endian correction unconditionally
  1357.          below.  */
  1358.       x = gen_rtx (MEM, mode,
  1359.                plus_constant (XEXP (x, 0),
  1360.                       GET_MODE_SIZE (mode) - total_size));
  1361. #endif
  1362.       spill_stack_slot[from_reg] = x;
  1363.       spill_stack_slot_width[from_reg] = total_size;
  1364.     }
  1365.  
  1366. #ifdef BYTES_BIG_ENDIAN
  1367.       /* On a big endian machine, the "address" of the slot
  1368.      is the address of the low part that fits its inherent mode.  */
  1369.       if (inherent_size < total_size)
  1370.     x = gen_rtx (MEM, GET_MODE (regno_reg_rtx[i]),
  1371.              plus_constant (XEXP (x, 0),
  1372.                     total_size - inherent_size));
  1373. #endif /* BYTES_BIG_ENDIAN */
  1374.  
  1375.       addr = XEXP (x, 0);
  1376.  
  1377.       /* If the stack slot is directly addressable, substitute
  1378.      the MEM we just got directly for the old REG.
  1379.      Otherwise, record the address; we will generate hairy code
  1380.      to compute the address in a register each time it is needed.  */
  1381.       if (memory_address_p (GET_MODE (regno_reg_rtx[i]), addr))
  1382.     reg_equiv_mem[i] = x;
  1383.       else
  1384.     reg_equiv_address[i] = XEXP (x, 0);
  1385.     }
  1386. }
  1387.  
  1388. /* Mark the slots in regs_ever_live for the hard regs
  1389.    used by pseudo-reg number REGNO.  */
  1390.  
  1391. void
  1392. mark_home_live (regno)
  1393.      int regno;
  1394. {
  1395.   register int i, lim;
  1396.   i = reg_renumber[regno];
  1397.   if (i < 0)
  1398.     return;
  1399.   lim = i + HARD_REGNO_NREGS (i, PSEUDO_REGNO_MODE (regno));
  1400.   while (i < lim)
  1401.     regs_ever_live[i++] = 1;
  1402. }
  1403.  
  1404. /* Kick all pseudos out of hard register REGNO.
  1405.    If GLOBAL is nonzero, try to find someplace else to put them.
  1406.    If DUMPFILE is nonzero, log actions taken on that file.
  1407.  
  1408.    Return nonzero if any pseudos needed to be kicked out
  1409.    or if this hard reg may appear explicitly in some instructions.  */
  1410.  
  1411. static int
  1412. spill_hard_reg (regno, global, dumpfile)
  1413.      register int regno;
  1414.      int global;
  1415.      FILE *dumpfile;
  1416. {
  1417.   int something_changed = 0;
  1418.   register int i;
  1419.  
  1420.   /* Spill every pseudo reg that was allocated to this reg
  1421.      or to something that overlaps this reg.  */
  1422.  
  1423.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  1424.     if (reg_renumber[i] >= 0
  1425.     && reg_renumber[i] <= regno
  1426.     && (reg_renumber[i] 
  1427.         + HARD_REGNO_NREGS (reg_renumber[i],
  1428.                 PSEUDO_REGNO_MODE (i))
  1429.         > regno))
  1430.       {
  1431.     /* If this register belongs solely to a basic block
  1432.        which needed no spilling, leave it be.  */
  1433.     if (regno != FRAME_POINTER_REGNUM
  1434.         && basic_block_needs
  1435.         && reg_basic_block[i] >= 0
  1436.         && basic_block_needs[reg_basic_block[i]] == 0)
  1437.       continue;
  1438.  
  1439.     /* Mark it as no longer having a hard register home.  */
  1440.     reg_renumber[i] = -1;
  1441.     /* We will need to scan everything again.  */
  1442.     something_changed = 1;
  1443.     if (global)
  1444.       {
  1445.         retry_global_alloc (i, forbidden_regs);
  1446.         /* Update regs_ever_live for new home (if any).  */
  1447.         mark_home_live (i);
  1448.         /* If something gets spilled to the stack,
  1449.            we must have a frame pointer, so spill the frame pointer.  */
  1450.         if (reg_renumber[i] == -1 && ! frame_pointer_needed)
  1451.           {
  1452.         frame_pointer_needed = 1;
  1453.         forbidden_regs[FRAME_POINTER_REGNUM] = 1;
  1454.         spill_hard_reg (FRAME_POINTER_REGNUM, global, dumpfile);
  1455.           }
  1456.       }
  1457.     alter_reg (i, regno);
  1458.     if (dumpfile)
  1459.       {
  1460.         if (reg_renumber[i] == -1)
  1461.           fprintf (dumpfile, " Register %d now on stack.\n\n", i);
  1462.         else
  1463.           fprintf (dumpfile, " Register %d now in %d.\n\n",
  1464.                i, reg_renumber[i]);
  1465.       }
  1466.       }
  1467.  
  1468.   return something_changed || regs_explicitly_used[i];
  1469. }
  1470.  
  1471. /* Find all paradoxical subregs within X and update reg_max_ref_width.  */
  1472.  
  1473. static rtx
  1474. scan_paradoxical_subregs (x)
  1475.      register rtx x;
  1476. {
  1477.   register int i;
  1478.   register char *fmt;
  1479.   register enum rtx_code code = GET_CODE (x);
  1480.  
  1481.   switch (code)
  1482.     {
  1483.     case CONST_INT:
  1484.     case CONST:
  1485.     case SYMBOL_REF:
  1486.     case LABEL_REF:
  1487.     case CONST_DOUBLE:
  1488.     case CC0:
  1489.     case PC:
  1490.     case REG:
  1491.     case USE:
  1492.     case CLOBBER:
  1493.       return;
  1494.  
  1495.     case SUBREG:
  1496.       if (GET_CODE (SUBREG_REG (x)) == REG
  1497.       && GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  1498.     reg_max_ref_width[REGNO (SUBREG_REG (x))]
  1499.       = GET_MODE_SIZE (GET_MODE (x));
  1500.       return;
  1501.     }
  1502.  
  1503.   fmt = GET_RTX_FORMAT (code);
  1504.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1505.     {
  1506.       if (fmt[i] == 'e')
  1507.     scan_paradoxical_subregs (XEXP (x, i));
  1508.       else if (fmt[i] == 'E')
  1509.     {
  1510.       register int j;
  1511.       for (j = XVECLEN (x, i) - 1; j >=0; j--)
  1512.         scan_paradoxical_subregs (XVECEXP (x, i, j));
  1513.     }
  1514.     }
  1515. }
  1516.  
  1517. struct hard_reg_n_uses { int regno; int uses; };
  1518.  
  1519. static int
  1520. hard_reg_use_compare (p1, p2)
  1521.      struct hard_reg_n_uses *p1, *p2;
  1522. {
  1523.   int tem = p1->uses - p2->uses;
  1524.   if (tem != 0) return tem;
  1525.   /* If regs are equally good, sort by regno,
  1526.      so that the results of qsort leave nothing to chance.  */
  1527.   return p1->regno - p2->regno;
  1528. }
  1529.  
  1530. /* Choose the order to consider regs for use as reload registers
  1531.    based on how much trouble would be caused by spilling one.
  1532.    Store them in order of decreasing preference in potential_reload_regs.  */
  1533.  
  1534. static void
  1535. order_regs_for_reload ()
  1536. {
  1537.   register int i;
  1538.   register int o = 0;
  1539.   int large = 0;
  1540.  
  1541.   struct hard_reg_n_uses hard_reg_n_uses[FIRST_PSEUDO_REGISTER];
  1542.  
  1543.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1544.     potential_reload_regs[i] = -1;
  1545.  
  1546.   /* Count number of uses of each hard reg by pseudo regs allocated to it
  1547.      and then order them by decreasing use.  */
  1548.  
  1549.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1550.     {
  1551.       hard_reg_n_uses[i].uses = 0;
  1552.       hard_reg_n_uses[i].regno = i;
  1553.     }
  1554.  
  1555.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  1556.     {
  1557.       if (reg_renumber[i] >= 0)
  1558.     hard_reg_n_uses[reg_renumber[i]].uses += reg_n_refs[i];
  1559.       large += reg_n_refs[i];
  1560.     }
  1561.  
  1562.   /* Now fixed registers (which cannot safely be used for reloading)
  1563.      get a very high use count so they will be considered least desirable.
  1564.      Registers used explicitly in the rtl code are almost as bad.  */
  1565.  
  1566.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1567.     {
  1568.       if (fixed_regs[i])
  1569.     hard_reg_n_uses[i].uses += large + 2;
  1570.       else if (regs_explicitly_used[i])
  1571.     hard_reg_n_uses[i].uses += large + 1;
  1572.     }
  1573.   hard_reg_n_uses[FRAME_POINTER_REGNUM].uses += large + 2;
  1574.  
  1575.   qsort (hard_reg_n_uses, FIRST_PSEUDO_REGISTER,
  1576.      sizeof hard_reg_n_uses[0], hard_reg_use_compare);
  1577.  
  1578.   /* Prefer registers not so far used, for use in temporary loading.
  1579.      Among them, prefer registers not preserved by calls.  */
  1580.  
  1581.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1582.     {
  1583. #ifdef REG_ALLOC_ORDER
  1584.       int regno = reg_alloc_order[i];
  1585. #else
  1586.       int regno = i;
  1587. #endif
  1588.       if (regs_ever_live[regno] == 0 && call_used_regs[regno]
  1589.       && ! fixed_regs[regno])
  1590.     potential_reload_regs[o++] = regno;
  1591.     }
  1592.  
  1593.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1594.     {
  1595. #ifdef REG_ALLOC_ORDER
  1596.       int regno = reg_alloc_order[i];
  1597. #else
  1598.       int regno = i;
  1599. #endif
  1600.       if (regs_ever_live[regno] == 0 && ! call_used_regs[regno]
  1601.       && regno != FRAME_POINTER_REGNUM)
  1602.     potential_reload_regs[o++] = regno;
  1603.     }
  1604.  
  1605.   /* Now add the regs that are already used,
  1606.      preferring those used less often.  */
  1607.  
  1608.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1609.     if (regs_ever_live[hard_reg_n_uses[i].regno] != 0)
  1610.       potential_reload_regs[o++] = hard_reg_n_uses[i].regno;
  1611.  
  1612. #if 0
  1613.   /* For regs that are used, don't prefer those not preserved by calls
  1614.      because those are likely to contain high priority things
  1615.      that are live for short periods of time.  */
  1616.  
  1617.   for (i = FIRST_PSEUDO_REGISTER - 1; i >= 0; i--)
  1618.     if (regs_ever_live[i] != 0 && ! call_used_regs[i])
  1619.       potential_reload_regs[o++] = i;
  1620. #endif
  1621. }
  1622.  
  1623. /* Reload pseudo-registers into hard regs around each insn as needed.
  1624.    Additional register load insns are output before the insn that needs it
  1625.    and perhaps store insns after insns that modify the reloaded pseudo reg.
  1626.  
  1627.    reg_last_reload_reg and reg_reloaded_contents keep track of
  1628.    which pseudo-registers are already available in reload registers.
  1629.    We update these for the reloads that we perform,
  1630.    as the insns are scanned.  */
  1631.  
  1632. static void
  1633. reload_as_needed (first, live_known)
  1634.      rtx first;
  1635.      int live_known;
  1636. {
  1637.   register rtx insn;
  1638.   register int i;
  1639.   int this_block = 0;
  1640.   rtx x;
  1641.  
  1642.   bzero (spill_reg_rtx, sizeof spill_reg_rtx);
  1643.   reg_last_reload_reg = (rtx *) alloca (max_regno * sizeof (rtx));
  1644.   bzero (reg_last_reload_reg, max_regno * sizeof (rtx));
  1645.   reg_has_output_reload = (char *) alloca (max_regno);
  1646.   for (i = 0; i < n_spills; i++)
  1647.     reg_reloaded_contents[i] = -1;
  1648.  
  1649.   for (insn = first; insn;)
  1650.     {
  1651.       register rtx next = NEXT_INSN (insn);
  1652.  
  1653.       /* Notice when we move to a new basic block.  */
  1654.       if (basic_block_needs && this_block + 1 < n_basic_blocks
  1655.       && insn == basic_block_head[this_block+1])
  1656.     ++this_block;
  1657.  
  1658.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  1659.       || GET_CODE (insn) == CALL_INSN)
  1660.     {
  1661.       /* If insn has no reloads, we want these to be zero, down below.  */
  1662.       bzero (reg_has_output_reload, max_regno);
  1663.       bzero (reg_is_output_reload, FIRST_PSEUDO_REGISTER);
  1664.  
  1665.       if (GET_MODE (insn) == VOIDmode)
  1666.         n_reloads = 0;
  1667.       /* First find the pseudo regs that must be reloaded for this insn.
  1668.          This info is returned in the tables reload_... (see reload.h).
  1669.          Also modify the body of INSN by substituting RELOAD
  1670.          rtx's for those pseudo regs.  */
  1671.       else
  1672.         find_reloads (insn, 1, spill_indirect_ok, live_known, spill_reg_order);
  1673.  
  1674.       if (n_reloads > 0)
  1675.         {
  1676.           /* If this block has not had spilling done,
  1677.          deactivate any optional reloads lest they
  1678.          try to use a spill-reg which isn't available here.
  1679.          If we have any non-optionals that need a spill reg, abort.  */
  1680.           if (basic_block_needs != 0
  1681.           && basic_block_needs[this_block] == 0)
  1682.         {
  1683.           for (i = 0; i < n_reloads; i++)
  1684.             {
  1685.               if (reload_optional[i])
  1686.             reload_in[i] = reload_out[i] = 0;
  1687.               else if (reload_reg_rtx[i] == 0)
  1688.             abort ();
  1689.             }
  1690.         }
  1691.  
  1692.           /* Now compute which reload regs to reload them into.  Perhaps
  1693.          reusing reload regs from previous insns, or else output
  1694.          load insns to reload them.  Maybe output store insns too.
  1695.          Record the choices of reload reg in reload_reg_rtx.  */
  1696.           choose_reload_regs (insn);
  1697.  
  1698.           /* Generate the insns to reload operands into or out of
  1699.          their reload regs.  */
  1700.           emit_reload_insns (insn);
  1701.  
  1702.           /* Substitute the chosen reload regs from reload_reg_rtx
  1703.          into the insn's body (or perhaps into the bodies of other
  1704.          load and store insn that we just made for reloading
  1705.          and that we moved the structure into).  */
  1706.           subst_reloads ();
  1707.         }
  1708.       /* Any previously reloaded spilled pseudo reg, stored in this insn,
  1709.          is no longer validly lying around to save a future reload.
  1710.          Note that this does not detect pseudos that were reloaded
  1711.          for this insn in order to be stored in
  1712.          (obeying register constraints).  That is correct; such reload
  1713.          registers ARE still valid.  */
  1714.       note_stores (PATTERN (insn), forget_old_reloads_1);
  1715.  
  1716.       /* Likewise for regs altered by auto-increment in this insn.
  1717.          But note that the reg-notes are not changed by reloading:
  1718.          they still contain the pseudo-regs, not the spill regs.  */
  1719.       for (x = REG_NOTES (insn); x; x = XEXP (x, 1))
  1720.         if (REG_NOTE_KIND (x) == REG_INC)
  1721.           {
  1722.         /* See if this pseudo reg was reloaded in this insn.
  1723.            If so, its last-reload info is still valid
  1724.            because it is based on this insn's reload.  */
  1725.         for (i = 0; i < n_reloads; i++)
  1726.           if (reload_out[i] == XEXP (x, 0))
  1727.             break;
  1728.  
  1729.         if (i != n_reloads)
  1730.           forget_old_reloads_1 (XEXP (x, 0));
  1731.           }
  1732.     }
  1733.       /* A reload reg's contents are unknown after a label.  */
  1734.       if (GET_CODE (insn) == CODE_LABEL)
  1735.     for (i = 0; i < n_spills; i++)
  1736.       reg_reloaded_contents[i] = -1;
  1737.  
  1738.       /* Don't assume a reload reg is still good after a call insn
  1739.      if it is a call-used reg.  */
  1740.       if (GET_CODE (insn) == CODE_LABEL || GET_CODE (insn) == CALL_INSN)
  1741.     for (i = 0; i < n_spills; i++)
  1742.       if (call_used_regs[spill_regs[i]])
  1743.         reg_reloaded_contents[i] = -1;
  1744.  
  1745.       /* In case registers overlap, allow certain insns to invalidate
  1746.      particular hard registers.  */
  1747.  
  1748. #ifdef INSN_CLOBBERS_REGNO_P
  1749.       for (i = 0 ; i < n_spills ; i++)
  1750.     if (INSN_CLOBBERS_REGNO_P (insn, spill_regs[i]))
  1751.       reg_reloaded_contents[i] = -1;
  1752. #endif
  1753.  
  1754.       insn = next;
  1755.  
  1756. #ifdef USE_C_ALLOCA
  1757.       alloca (0);
  1758. #endif
  1759.     }
  1760. }
  1761.  
  1762. /* Discard all record of any value reloaded from X,
  1763.    or reloaded in X from someplace else;
  1764.    unless X is an output reload reg of the current insn.
  1765.  
  1766.    X may be a hard reg (the reload reg)
  1767.    or it may be a pseudo reg that was reloaded from.
  1768.  
  1769.    This function is not called for instructions generated by reload.  */
  1770.  
  1771. static void
  1772. forget_old_reloads_1 (x)
  1773.      rtx x;
  1774. {
  1775.   register int regno;
  1776.   int nr;
  1777.  
  1778.   if (GET_CODE (x) != REG)
  1779.     return;
  1780.  
  1781.   regno = REGNO (x);
  1782.  
  1783.   if (regno >= FIRST_PSEUDO_REGISTER)
  1784.     nr = 1;
  1785.   else
  1786.     {
  1787.       int i;
  1788.       nr = HARD_REGNO_NREGS (regno, GET_MODE (x));
  1789.       /* Storing into a spilled-reg invalidates its contents.
  1790.      This can happen if a block-local pseudo is allocated to that reg
  1791.      and it wasn't spilled because this block's total need is 0.
  1792.      Then some insn might have an optional reload and use this reg.  */
  1793.       for (i = 0; i < nr; i++)
  1794.     if (spill_reg_order[regno + i] >= 0
  1795.         /* But don't do this if the reg actually serves as an output
  1796.            reload reg in the current instruction.  */
  1797.         && reg_is_output_reload[regno + i] == 0)
  1798.       reg_reloaded_contents[spill_reg_order[regno + i]] = -1;
  1799.     }
  1800.  
  1801.   /* Since value of X has changed,
  1802.      forget any value previously copied from it.  */
  1803.  
  1804.   while (nr-- > 0)
  1805.     /* But don't forget a copy if this is the output reload
  1806.        that establishes the copy's validity.  */
  1807.     if (reg_has_output_reload[regno + nr] == 0)
  1808.       reg_last_reload_reg[regno + nr] = 0;
  1809. }
  1810.  
  1811. /* Comparison function for qsort to decide which of two reloads
  1812.    should be handled first.  *P1 and *P2 are the reload numbers.  */
  1813.  
  1814. static int
  1815. reload_reg_class_lower (p1, p2)
  1816.      short *p1, *p2;
  1817. {
  1818.   register int r1 = *p1, r2 = *p2;
  1819.   register int t;
  1820.   register enum machine_mode mode1, mode2;
  1821.   
  1822.   /* Consider required reloads before optional ones.  */
  1823.   t = reload_optional[r1] - reload_optional[r2];
  1824.   if (t != 0)
  1825.     return t;
  1826.   /* Consider all multi-reg groups first.
  1827.      This is safe because `reload' fills all group-need before
  1828.      filling all non-group need.  */
  1829.   mode1 = (reload_inmode[r1] == VOIDmode ? reload_outmode[r1] : reload_inmode[r1]);
  1830.   mode2 = (reload_inmode[r2] == VOIDmode ? reload_outmode[r2] : reload_inmode[r2]);
  1831.   t = (CLASS_MAX_NREGS (reload_reg_class[r2], mode2)
  1832.        - CLASS_MAX_NREGS (reload_reg_class[r1], mode1));
  1833.   if (t != 0)
  1834.     return t;
  1835.   /* Consider reloads in order of increasing reg-class number.  */
  1836.   t = (int) reload_reg_class[r1] - (int) reload_reg_class[r2];
  1837.   if (t != 0) return t;
  1838.   /* If reloads are equally urgent, sort by reload number,
  1839.      so that the results of qsort leave nothing to chance.  */
  1840.   return r1 - r2;
  1841. }
  1842.  
  1843. /* The following tables are indexed by register number,
  1844.    not by spill_regs index.  */
  1845.  
  1846. /* 1 if reg is in use as a reload reg for a RELOAD_OTHER reload.  */
  1847. static char reload_reg_in_use[FIRST_PSEUDO_REGISTER];
  1848. /* 1 if reg is in use for a RELOAD_FOR_INPUT_RELOAD_ADDRESS reload.  */
  1849. static char reload_reg_in_use_for_inputs[FIRST_PSEUDO_REGISTER];
  1850. /* 1 if reg is in use for a RELOAD_FOR_OUTPUT_RELOAD_ADDRESS reload.  */
  1851. static char reload_reg_in_use_for_outputs[FIRST_PSEUDO_REGISTER];
  1852. /* 1 if reg is in use for a RELOAD_FOR_OPERAND_ADDRESS reload.  */
  1853. static char reload_reg_in_use_for_operands[FIRST_PSEUDO_REGISTER];
  1854.  
  1855. /* 1 if reg is in use as a reload reg for any sort of reload.  */
  1856. static char reload_reg_in_use_at_all[FIRST_PSEUDO_REGISTER];
  1857.  
  1858. /* Mark reg REGNO as in use for a reload of the sort spec'd by WHEN_NEEDED.  */
  1859.  
  1860. static void
  1861. mark_reload_reg_in_use (regno, when_needed)
  1862.      int regno;
  1863.      enum reload_when_needed when_needed;
  1864. {
  1865.   switch (when_needed)
  1866.     {
  1867.     case RELOAD_OTHER:
  1868.       reload_reg_in_use[regno] = 1;
  1869.       break;
  1870.  
  1871.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  1872.       reload_reg_in_use_for_inputs[regno] = 1;
  1873.       break;
  1874.  
  1875.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  1876.       reload_reg_in_use_for_outputs[regno] = 1;
  1877.       break;
  1878.  
  1879.     case RELOAD_FOR_OPERAND_ADDRESS:
  1880.       reload_reg_in_use_for_operands[regno] = 1;
  1881.       break;
  1882.     }
  1883.   reload_reg_in_use_at_all[regno] = 1;
  1884. }
  1885.  
  1886. /* 1 if reg REGNO is free as a reload reg for a reload of the sort
  1887.    specified by WHEN_NEEDED.  */
  1888.  
  1889. static int
  1890. reload_reg_free_p (regno, when_needed)
  1891.      int regno;
  1892.      enum reload_when_needed when_needed;
  1893. {
  1894.   /* In use for a RELOAD_OTHER means it's not available for anything.  */
  1895.   if (reload_reg_in_use[regno])
  1896.     return 0;
  1897.   switch (when_needed)
  1898.     {
  1899.     case RELOAD_OTHER:
  1900.       /* In use for anything means not available for a RELOAD_OTHER.  */
  1901.       return ! reload_reg_in_use_at_all[regno];
  1902.  
  1903.       /* The other three kinds of use can share a register.  */
  1904.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  1905.       return ! reload_reg_in_use_for_inputs[regno];
  1906.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  1907.       return ! reload_reg_in_use_for_outputs[regno];
  1908.     case RELOAD_FOR_OPERAND_ADDRESS:
  1909.       return ! reload_reg_in_use_for_operands[regno];
  1910.     }
  1911. }
  1912.  
  1913. /* Return 1 if the value in reload reg REGNO, as used by a reload
  1914.    needed for the part of the insn specified by WHEN_NEEDED,
  1915.    is not in use for a reload in any prior part of the insn.  */
  1916.  
  1917. static int
  1918. reload_reg_free_before_p (regno, when_needed)
  1919.      int regno;
  1920.      enum reload_when_needed when_needed;
  1921. {
  1922.   switch (when_needed)
  1923.     {
  1924.     case RELOAD_OTHER:
  1925.       /* Since a RELOAD_OTHER reload claims the reg for the entire insn,
  1926.      its use starts from the beginning, so nothing can use it earlier.  */
  1927.       return 1;
  1928.  
  1929.       /* If this use is for part of the insn,
  1930.      check the reg is not in use for any prior part.  */
  1931.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  1932.       if (reload_reg_in_use_for_operands[regno])
  1933.     return 0;
  1934.     case RELOAD_FOR_OPERAND_ADDRESS:
  1935.       if (reload_reg_in_use_for_inputs[regno])
  1936.     return 0;
  1937.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  1938.       return 1;
  1939.     }
  1940. }
  1941.  
  1942. /* Return 1 if the value in reload reg REGNO, as used by a reload
  1943.    needed for the part of the insn specified by WHEN_NEEDED,
  1944.    is still available in REGNO at the end of the insn.  */
  1945.  
  1946. static int
  1947. reload_reg_reaches_end_p (regno, when_needed)
  1948.      int regno;
  1949.      enum reload_when_needed when_needed;
  1950. {
  1951.   switch (when_needed)
  1952.     {
  1953.     case RELOAD_OTHER:
  1954.       /* Since a RELOAD_OTHER reload claims the reg for the entire insn,
  1955.      its value must reach the end.  */
  1956.       return 1;
  1957.  
  1958.       /* If this use is for part of the insn,
  1959.      its value reaches if no subsequent part uses the same register.  */
  1960.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  1961.       if (reload_reg_in_use_for_operands[regno])
  1962.     return 0;
  1963.     case RELOAD_FOR_OPERAND_ADDRESS:
  1964.       if (reload_reg_in_use_for_outputs[regno])
  1965.     return 0;
  1966.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  1967.       return 1;
  1968.     }
  1969. }
  1970.  
  1971. /* Vector of reload-numbers showing the order in which the reloads should
  1972.    be processed.  */
  1973. short reload_order[MAX_RELOADS];
  1974.  
  1975. /* Indexed by reload number, 1 if incoming value
  1976.    inherited from previous insns.  */
  1977. char reload_inherited[MAX_RELOADS];
  1978.  
  1979. /* If non-zero, this is a place to get the value of the reload,
  1980.    rather than using reload_in.  */
  1981. rtx reload_override_in[MAX_RELOADS];
  1982.  
  1983. /* For each reload, the index in spill_regs of the spill register used,
  1984.    or -1 if we did not need one of the spill registers for this reload.  */
  1985. int reload_spill_index[MAX_RELOADS];
  1986.  
  1987. /* Assign hard reg targets for the pseudo-registers we must reload
  1988.    into hard regs for this insn.
  1989.    Also output the instructions to copy them in and out of the hard regs.
  1990.  
  1991.    For machines with register classes, we are responsible for
  1992.    finding a reload reg in the proper class.  */
  1993.  
  1994. static void
  1995. choose_reload_regs (insn)
  1996.      rtx insn;
  1997. {
  1998.   register int j;
  1999.   int have_groups = 0;
  2000.   /* Non-zero means we must reuse spill regs for multiple reloads in this insn
  2001.      or we will not have enough spill regs.  */
  2002.   int must_reuse = 0;
  2003.   rtx original_reload_reg_rtx[MAX_RELOADS];
  2004.  
  2005.   /* See if we have more mandatory reloads than spill regs.
  2006.      If so, then we cannot risk optimizations that could prevent
  2007.      reloads from sharing one spill register.  */
  2008.  
  2009.   {
  2010.     int tem = 0;
  2011.     for (j = 0; j < n_reloads; j++)
  2012.       if (! reload_optional[j] && reload_reg_rtx[j] == 0)
  2013.     tem++;
  2014.     if (tem > n_spills)
  2015.       must_reuse = 1;
  2016.   }
  2017.  
  2018.   bcopy (reload_reg_rtx, original_reload_reg_rtx, sizeof (reload_reg_rtx));
  2019.  
  2020.   /* If we fail to get enough regs without must_reuse,
  2021.      set must_reuse and jump back here.  */
  2022.  retry:
  2023.   bzero (reload_inherited, MAX_RELOADS);
  2024.   bzero (reload_override_in, MAX_RELOADS * sizeof (rtx));
  2025.   bzero (reload_reg_in_use, FIRST_PSEUDO_REGISTER);
  2026.   bzero (reload_reg_in_use_at_all, FIRST_PSEUDO_REGISTER);
  2027.   bzero (reload_reg_in_use_for_inputs, FIRST_PSEUDO_REGISTER);
  2028.   bzero (reload_reg_in_use_for_outputs, FIRST_PSEUDO_REGISTER);
  2029.   bzero (reload_reg_in_use_for_operands, FIRST_PSEUDO_REGISTER);
  2030.  
  2031.   /* In order to be certain of getting the registers we need,
  2032.      we must sort the reloads into order of increasing register class.
  2033.      Then our grabbing of reload registers will parallel the process
  2034.      that provided the reload registers.  */
  2035.  
  2036.   /* Also note whether any of the reloads wants a consecutive group of regs.
  2037.      When that happens, we must when processing the non-group reloads
  2038.      avoid (when possible) using a reload reg that would break up a group.  */
  2039.  
  2040.   /* This used to look for an existing reloaded home for all
  2041.      of the reloads, and only then perform any new reloads.
  2042.      But that could lose if the reloads were done out of reg-class order
  2043.      because a later reload with a looser constraint might have an old
  2044.      home in a register needed by an earlier reload with a tighter constraint.
  2045.      It would be possible with even hairier code to detect such cases
  2046.      and handle them, but it doesn't seem worth while yet.  */
  2047.  
  2048.   for (j = 0; j < n_reloads; j++)
  2049.     {
  2050.       enum machine_mode mode;
  2051.       reload_order[j] = j;
  2052.       reload_spill_index[j] = -1;
  2053.       mode = (reload_inmode[j] == VOIDmode
  2054.           || GET_MODE_SIZE (reload_outmode[j]) > GET_MODE_SIZE (reload_inmode[j])
  2055.           ? reload_outmode[j] : reload_inmode[j]);
  2056.  
  2057.       if (CLASS_MAX_NREGS (reload_reg_class[j], mode) > 1)
  2058.     have_groups = 1;
  2059.       /* If we have already decided to use a certain register,
  2060.      don't use it in another way.  */
  2061.       if (reload_reg_rtx[j])
  2062.     mark_reload_reg_in_use (REGNO (reload_reg_rtx[j]), reload_when_needed[j]);
  2063.     }
  2064.  
  2065.   if (n_reloads > 1)
  2066.     qsort (reload_order, n_reloads, sizeof (short), reload_reg_class_lower);
  2067.  
  2068.   for (j = 0; j < n_reloads; j++)
  2069.     {
  2070.       register int r = reload_order[j];
  2071.       register int i;
  2072.       register rtx new;
  2073.       enum machine_mode reload_mode = reload_inmode[r];
  2074.       int h1_ok, h2_ok, h3_ok;
  2075.  
  2076.       /* Ignore reloads that got marked inoperative.  */
  2077.       if (reload_out[r] == 0 && reload_in[r] == 0)
  2078.     continue;
  2079.  
  2080.       if (GET_MODE_SIZE (reload_outmode[r]) > GET_MODE_SIZE (reload_mode))
  2081.     reload_mode = reload_outmode[r];
  2082.       if (reload_strict_low[r])
  2083.     reload_mode = GET_MODE (SUBREG_REG (reload_out[r]));
  2084.  
  2085.       /* No need to find a reload-register if find_reloads chose one.  */
  2086.  
  2087.       if (reload_reg_rtx[r] != 0)
  2088.     continue;
  2089.  
  2090.       /* First see if this pseudo is already available as reloaded
  2091.      for a previous insn.
  2092.      This feature is disabled for multi-register groups
  2093.      because we haven't yet any way to tell whether the entire
  2094.      value is properly preserved.
  2095.      It is also disabled when there are other reloads for mult-register
  2096.      groups, lest the inherited reload reg break up a needed group.  */
  2097.  
  2098.       {
  2099.     register int regno = -1;
  2100.  
  2101.     if (reload_in[r] == 0)
  2102.       ;
  2103.     else if (GET_CODE (reload_in[r]) == REG)
  2104.       regno = REGNO (reload_in[r]);
  2105.     else if (GET_CODE (reload_in_reg[r]) == REG)
  2106.       regno = REGNO (reload_in_reg[r]);
  2107. #if 0
  2108.     /* This won't work, since REGNO can be a pseudo reg number.
  2109.        Also, it takes much more hair to keep track of all the things
  2110.        that can invalidate an inherited reload of part of a pseudoreg.  */
  2111.     else if (GET_CODE (reload_in[r]) == SUBREG
  2112.          && GET_CODE (SUBREG_REG (reload_in[r])) == REG)
  2113.       regno = REGNO (SUBREG_REG (reload_in[r])) + SUBREG_WORD (reload_in[r]);
  2114. #endif
  2115.  
  2116.     if (regno >= 0
  2117.         && reg_last_reload_reg[regno] != 0
  2118.         && ! have_groups
  2119.         /* See comment at next use of must_reuse.  */
  2120.         && ! must_reuse)
  2121.       {
  2122.         i = spill_reg_order[REGNO (reg_last_reload_reg[regno])];
  2123.  
  2124.         if (reg_reloaded_contents[i] == regno
  2125.         && HARD_REGNO_MODE_OK (spill_regs[i], reload_mode)
  2126.         && TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[r]],
  2127.                       spill_regs[i])
  2128.         && reload_reg_free_p (spill_regs[i], reload_when_needed[r])
  2129.         && reload_reg_free_before_p (spill_regs[i],
  2130.                          reload_when_needed[r]))
  2131.           {
  2132.         /* Mark the register as in use for this part of the insn.  */
  2133.         mark_reload_reg_in_use (spill_regs[i], reload_when_needed[r]);
  2134.         reload_reg_rtx[r] = reg_last_reload_reg[regno];
  2135.         reload_inherited[r] = 1;
  2136.         reload_spill_index[r] = i;
  2137.           }
  2138.       }
  2139.       }
  2140.  
  2141.       /* Here's another way to see if the value is already lying around.  */
  2142.       if (reload_in[r] != 0
  2143.       && reload_reg_rtx[r] == 0
  2144.       && reload_out[r] == 0
  2145.       && (CONSTANT_P (reload_in[r])
  2146.           || GET_CODE (reload_in[r]) == PLUS
  2147.           || GET_CODE (reload_in[r]) == REG
  2148.           || GET_CODE (reload_in[r]) == MEM)
  2149.       && ! have_groups
  2150.       /* This optimization can prevent this reload from reusing
  2151.          a spill reg used for another reload.  That could take away
  2152.          a spill reg that another reload will need.  If we cannot
  2153.          be sure there will still be enough spill regs,
  2154.          don't do this optimization.  */
  2155.       && ! must_reuse)
  2156.     {
  2157.       register rtx equiv
  2158.         = find_equiv_reg (reload_in[r], insn, reload_reg_class[r],
  2159.                   -1, 0, 0, reload_mode);
  2160.       int regno;
  2161.  
  2162.       if (equiv != 0)
  2163.         regno = REGNO (equiv);
  2164.  
  2165.       /* If we found a spill reg, reject it unless it is free
  2166.          and of the desired class.  */
  2167.       if (equiv != 0 && GET_CODE (equiv) == REG
  2168.           && spill_reg_order[regno] >= 0
  2169.           && reload_reg_free_before_p (regno, reload_when_needed[r]))
  2170.         {
  2171.           if (! TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[r]],
  2172.                        regno))
  2173.         equiv = 0;
  2174.         }
  2175.  
  2176.       if (equiv != 0 && reload_reg_in_use_at_all[regno])
  2177.         equiv = 0;
  2178.  
  2179.       if (equiv != 0 && ! HARD_REGNO_MODE_OK (regno, reload_mode))
  2180.         equiv = 0;
  2181.  
  2182.       /* We found a register that contains the value we need.
  2183.          If this register is the same as an `earlyclobber' operand
  2184.          of the current insn, just mark it as a place to reload from
  2185.          since we can't use it as the reload register itself.  */
  2186.  
  2187.       if (equiv != 0)
  2188.         for (i = 0; i < n_earlyclobbers; i++)
  2189.           if (reg_overlap_mentioned_p (equiv, reload_earlyclobbers[i]))
  2190.         {
  2191.           reload_override_in[r] = equiv;
  2192.           equiv = 0;
  2193.           break;
  2194.         }
  2195.  
  2196.       /* If we found an equivalent reg, say no code need be generated
  2197.          to load it, and use it as our reload reg.  */
  2198.       if (equiv != 0
  2199.           && REGNO (equiv) != FRAME_POINTER_REGNUM)
  2200.         {
  2201.           reload_reg_rtx[r] = equiv;
  2202.           reload_inherited[r] = 1;
  2203.           /* If it is a spill reg,
  2204.          mark the spill reg as in use for this insn.  */
  2205.           i = spill_reg_order[REGNO (equiv)];
  2206.           if (i >= 0)
  2207.         {
  2208.           int nr = HARD_REGNO_NREGS (spill_regs[i], reload_mode);
  2209.           while (nr > 0)
  2210.             mark_reload_reg_in_use (REGNO (equiv) + --nr,
  2211.                         reload_when_needed[r]);
  2212.         }
  2213.         }
  2214.     }
  2215.  
  2216.       /* If it isn't lying around, and isn't optional,
  2217.      find a place to reload it into.  */
  2218.       if (reload_reg_rtx[r] != 0 || reload_optional[r] != 0)
  2219.     continue;
  2220.  
  2221.       /* Value not lying around; find a register to reload it into.
  2222.      Here I is not a regno, it is an index into spill_regs.  */
  2223.       i = n_spills;
  2224.  
  2225. #if 0
  2226.       /* The following is no longer needed now that all multi-register
  2227.      (group) reloads are processed before all solitary register reloads
  2228.      (due to changes in `reg_class_lower_p' and `reload'.  */
  2229.       /* The following also fails to test HARD_REGNO_MODE_OK appropriately,
  2230.      which was hard to fix because we don't know the mode that the
  2231.      group might have that would want this register.  */
  2232.  
  2233.       /* If we want just one reg, and other reloads want groups,
  2234.      first try to find a reg that can't be part of a group.  */
  2235.       if (have_groups
  2236.       && CLASS_MAX_NREGS (reload_reg_class[r], reload_mode) == 1)
  2237.     for (i = 0; i < n_spills; i++)
  2238.       {
  2239.         int regno = spill_regs[i];
  2240.         int class = (int) reload_reg_class[r];
  2241.         if (reload_reg_in_use_at_all[regno] == 0
  2242.         && TEST_HARD_REG_BIT (reg_class_contents[class],
  2243.                       regno)
  2244.         && !(regno + 1 < FIRST_PSEUDO_REGISTER
  2245.              && spill_reg_order[regno + 1] >= 0
  2246.              && reload_reg_in_use_at_all[regno + 1] == 0
  2247.              && TEST_HARD_REG_BIT (reg_class_contents[class],
  2248.                        regno + 1))
  2249.         && !(regno > 0
  2250.              && spill_reg_order[regno - 1] >= 0
  2251.              && reload_reg_in_use_at_all[regno - 1] == 0
  2252.              && TEST_HARD_REG_BIT (reg_class_contents[class],
  2253.                        regno - 1)))
  2254.           break;
  2255.       }
  2256.  
  2257.       /* If that didn't work, try to find a register that has only one
  2258.      neighbor that could make a group with it.  That way, if the
  2259.      available registers are three consecutive ones, we avoid taking
  2260.      the middle one (which would leave us with no possible groups).  */
  2261.  
  2262.       if (have_groups
  2263.       && CLASS_MAX_NREGS (reload_reg_class[r], reload_mode) == 1
  2264.       && i == n_spills)
  2265.     for (i = 0; i < n_spills; i++)
  2266.       {
  2267.         int regno = spill_regs[i];
  2268.         int class = (int) reload_reg_class[r];
  2269.         if (reload_reg_in_use_at_all[regno] == 0
  2270.         && TEST_HARD_REG_BIT (reg_class_contents[class],
  2271.                       regno)
  2272.         && (!(regno + 1 < FIRST_PSEUDO_REGISTER
  2273.               && spill_reg_order[regno + 1] >= 0
  2274.               && reload_reg_in_use_at_all[regno + 1] == 0
  2275.               && TEST_HARD_REG_BIT (reg_class_contents[class],
  2276.                         regno + 1))
  2277.             || !(regno > 0
  2278.              && spill_reg_order[regno - 1] >= 0
  2279.              && reload_reg_in_use_at_all[regno - 1] == 0
  2280.              && TEST_HARD_REG_BIT (reg_class_contents[class],
  2281.                            regno - 1))))
  2282.           break;
  2283.       }
  2284. #endif
  2285.  
  2286.       /* Now, if we want a single register and haven't yet found one,
  2287.      take any reg in the right class and not in use.
  2288.      If we want a consecutive group, here is where we look for it.  */
  2289.       if (i == n_spills)
  2290.     {
  2291.       int pass;
  2292.       /* If we put this reload ahead, thinking it is a group,
  2293.          then insist on finding a group.  Otherwise we can grab a
  2294.          reg that some other reload needs. 
  2295.          (That can happen when we have a 68000 DATA_OR_FP_REG
  2296.          which is a group of data regs or one fp reg.)
  2297.          ??? Really it would be nicer to have smarter handling
  2298.          for that kind of reg class, where a problem like this is normal.
  2299.          Perhaps those classes should be avoided for reloading
  2300.          by use of more alternatives.  */
  2301.       int force_group
  2302.         = (CLASS_MAX_NREGS (reload_reg_class[r], reload_mode) > 1);
  2303.       /* We need not be so restrictive if there are no more reloads
  2304.          for this insn.  */
  2305.       if (j + 1 == n_reloads)
  2306.         force_group = 0;
  2307.  
  2308.       for (pass = 0; pass < 2; pass++)
  2309.         {
  2310.           for (i = 0; i < n_spills; i++)
  2311.         {
  2312.           int class = (int) reload_reg_class[r];
  2313.           if (reload_reg_free_p (spill_regs[i], reload_when_needed[r])
  2314.               && TEST_HARD_REG_BIT (reg_class_contents[class],
  2315.                         spill_regs[i])
  2316.               /* Look first for regs to share, then for unshared.  */
  2317.               && (pass || reload_reg_in_use_at_all[spill_regs[i]]))
  2318.             {
  2319.               int nr = HARD_REGNO_NREGS (spill_regs[i], reload_mode);
  2320.               /* Avoid the problem where spilling a GENERAL_OR_FP_REG
  2321.              (on 68000) got us two FP regs.  If NR is 1,
  2322.              we would reject both of them.  */
  2323.               if (force_group)
  2324.             nr = CLASS_MAX_NREGS (reload_reg_class[r], reload_mode);
  2325.               /* If we need only one reg, we have already won.  */
  2326.               if (nr == 1)
  2327.             {
  2328.               /* But reject a single reg if we demand a group.  */
  2329.               if (force_group)
  2330.                 continue;
  2331.               break;
  2332.             }
  2333.               /* Otherwise check that as many consecutive regs as we need
  2334.              are available here.
  2335.              Also, don't use for a group registers that are
  2336.              needed for nongroups.  */
  2337.               if (HARD_REGNO_MODE_OK (spill_regs[i], reload_mode)
  2338.               && ! counted_for_nongroups[spill_regs[i]])
  2339.             while (nr > 1)
  2340.               {
  2341.                 int regno = spill_regs[i] + nr - 1;
  2342.                 if (!(TEST_HARD_REG_BIT (reg_class_contents[class],
  2343.                              regno)
  2344.                   && spill_reg_order[regno] >= 0
  2345.                   && reload_reg_free_p (regno, reload_when_needed[r])
  2346.                   && ! counted_for_nongroups[regno]))
  2347.                   break;
  2348.                 nr--;
  2349.               }
  2350.               if (nr == 1)
  2351.             break;
  2352.             }
  2353.         }
  2354.           /* If find something on pass 1, omit pass 2.  */
  2355.           if (i < n_spills)
  2356.         break;
  2357.         }
  2358.     }
  2359.  
  2360.       /* We should have found a spill register by now.  */
  2361.       if (i == n_spills)
  2362.     {
  2363.       if (must_reuse)
  2364.         abort ();
  2365.       bcopy (original_reload_reg_rtx, reload_reg_rtx, sizeof (reload_reg_rtx));
  2366.       must_reuse = 1;
  2367.       goto retry;
  2368.     }
  2369.  
  2370.       /* Mark as in use for this insn the reload regs we use for this.  */
  2371.       {
  2372.     int nr = HARD_REGNO_NREGS (spill_regs[i], reload_mode);
  2373.     while (nr > 0)
  2374.       {
  2375.         mark_reload_reg_in_use (spill_regs[i] + --nr,
  2376.                     reload_when_needed[r]);
  2377.         reg_reloaded_contents[spill_reg_order[spill_regs[i] + nr]] = -1;
  2378.       }
  2379.       }
  2380.  
  2381.       new = spill_reg_rtx[i];
  2382.  
  2383.       if (new == 0 || GET_MODE (new) != reload_mode)
  2384.     spill_reg_rtx[i] = new = gen_rtx (REG, reload_mode, spill_regs[i]);
  2385.  
  2386.       reload_reg_rtx[r] = new;
  2387.       reload_spill_index[r] = i;
  2388.  
  2389.       /* Detect when the reload reg can't hold the reload mode.
  2390.      This used to be one `if', but Sequent compiler can't handle that.  */
  2391.       if (HARD_REGNO_MODE_OK (REGNO (reload_reg_rtx[r]), reload_mode))
  2392.     if (! (reload_in[r] != 0
  2393.            && ! HARD_REGNO_MODE_OK (REGNO (reload_reg_rtx[r]),
  2394.                     GET_MODE (reload_in[r]))))
  2395.       if (! (reload_out[r] != 0
  2396.          && ! HARD_REGNO_MODE_OK (REGNO (reload_reg_rtx[r]),
  2397.                       GET_MODE (reload_out[r]))))
  2398.         /* The reg is OK.  */
  2399.         continue;
  2400.  
  2401.       /* The reg is not OK.  */
  2402.       {
  2403.     if (asm_noperands (PATTERN (insn)) < 0)
  2404.       /* It's the compiler's fault.  */
  2405.       abort ();
  2406.     /* It's the user's fault; the operand's mode and constraint
  2407.        don't match.  Disable this reload so we don't crash in final.  */
  2408.     error_for_asm (insn,
  2409.                "`asm' operand constraint incompatible with operand size");
  2410.     reload_in[r] = 0;
  2411.     reload_out[r] = 0;
  2412.     reload_reg_rtx[r] = 0;
  2413.     reload_optional[r] = 1;
  2414.       }
  2415.     }
  2416.  
  2417.   /* If we thought we could inherit a reload, because it seemed that
  2418.      nothing else wanted the same reload register earlier in the insn,
  2419.      verify that assumption, now that all reloads have been assigned.  */
  2420.  
  2421.   for (j = 0; j < n_reloads; j++)
  2422.     {
  2423.       register int r = reload_order[j];
  2424.  
  2425.       if (reload_inherited[r] && reload_reg_rtx[r] != 0
  2426.       && ! reload_reg_free_before_p (REGNO (reload_reg_rtx[r]),
  2427.                      reload_when_needed[r]))
  2428.     reload_inherited[r] = 0;
  2429.  
  2430.       /* If we found a better place to reload from,
  2431.      validate it in the same fashion, if it is a reload reg.  */
  2432.       if (reload_override_in[r]
  2433.       && GET_CODE (reload_override_in[r]) == REG
  2434.       && spill_reg_order[REGNO (reload_override_in[r])] >= 0
  2435.       && ! reload_reg_free_before_p (REGNO (reload_override_in[r]),
  2436.                      reload_when_needed[r]))
  2437.     reload_override_in[r] = 0;
  2438.     }
  2439.  
  2440.   /* Now that reload_override_in is known valid,
  2441.      actually override reload_in.  */
  2442.   for (j = 0; j < n_reloads; j++)
  2443.     if (reload_override_in[j])
  2444.       reload_in[j] = reload_override_in[j];
  2445.  
  2446.   /* For all the spill regs newly reloaded in this instruction,
  2447.      record what they were reloaded from, so subsequent instructions
  2448.      can inherit the reloads.  */
  2449.  
  2450.   for (j = 0; j < n_reloads; j++)
  2451.     {
  2452.       register int r = reload_order[j];
  2453.       register int i = reload_spill_index[r];
  2454.  
  2455.       /* I is nonneg if this reload used one of the spill regs.
  2456.      If reload_reg_rtx[r] is 0, this is an optional reload
  2457.      that we opted to ignore.  */
  2458.       if (i >= 0 && reload_reg_rtx[r] != 0)
  2459.     {
  2460.       /* Maybe the spill reg contains a copy of reload_out.  */
  2461.       if (reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG)
  2462.         {
  2463.           register int nregno = REGNO (reload_out[r]);
  2464.           reg_last_reload_reg[nregno] = reload_reg_rtx[r];
  2465.           reg_reloaded_contents[i] = nregno;
  2466.           reg_has_output_reload[nregno] = 1;
  2467.           reg_is_output_reload[spill_regs[i]] = 1;
  2468.           if (reload_when_needed[r] != RELOAD_OTHER)
  2469.         abort ();
  2470.         }
  2471.       /* Maybe the spill reg contains a copy of reload_in.  */
  2472.       else if (reload_out[r] == 0
  2473.            && (GET_CODE (reload_in[r]) == REG
  2474.                || GET_CODE (reload_in_reg[r]) == REG))
  2475.         {
  2476.           register int nregno;
  2477.           if (GET_CODE (reload_in[r]) == REG)
  2478.         nregno = REGNO (reload_in[r]);
  2479.           else
  2480.         nregno = REGNO (reload_in_reg[r]);
  2481.  
  2482.           /* If there are two separate reloads (one in and one out)
  2483.          for the same (hard or pseudo) reg,
  2484.          leave reg_last_reload_reg set 
  2485.          based on the output reload.
  2486.          Otherwise, set it from this input reload.  */
  2487.           if (!reg_has_output_reload[nregno])
  2488.         {
  2489.           reg_last_reload_reg[nregno] = reload_reg_rtx[r];
  2490.           reg_reloaded_contents[i] = nregno;
  2491.  
  2492.           /* But don't do so if another input reload
  2493.              will clobber this one's value.  */
  2494.           if (! reload_reg_reaches_end_p (spill_regs[i],
  2495.                           reload_when_needed[r]))
  2496.             reg_reloaded_contents[i] = -1;
  2497.         }
  2498.         }
  2499.       /* Otherwise, the spill reg doesn't contain a copy of any reg.
  2500.          Clear out its records, lest it be taken for a copy
  2501.          of reload_in when that is no longer true.  */
  2502.       else
  2503.         reg_reloaded_contents[i] = -1;
  2504.     }
  2505.  
  2506.       /* The following if-statement was #if 0'd in 1.34 (or before...).
  2507.      It's reenabled in 1.35 because supposedly nothing else
  2508.      deals with this problem.  */
  2509.  
  2510.       /* If a register gets output-reloaded from a non-spill register,
  2511.      that invalidates any previous reloaded copy of it.
  2512.      But forget_old_reloads_1 won't get to see it, because
  2513.      it thinks only about the original insn.  So invalidate it here.  */
  2514.       if (i < 0 && reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG)
  2515.     {
  2516.       register int nregno = REGNO (reload_out[r]);
  2517.       reg_last_reload_reg[nregno] = 0;
  2518.       reg_has_output_reload[nregno] = 1;
  2519.     }
  2520.     }
  2521. }
  2522.  
  2523. /* Output insns to reload values in and out of the chosen reload regs.  */
  2524.  
  2525. static void
  2526. emit_reload_insns (insn)
  2527.      rtx insn;
  2528. {
  2529.   register int j;
  2530.   rtx first_output_reload_insn = NEXT_INSN (insn);
  2531.   rtx first_other_reload_insn = insn;
  2532.   rtx first_operand_address_reload_insn = insn;
  2533.   int special;
  2534.  
  2535.   /* Now output the instructions to copy the data into and out of the
  2536.      reload registers.  Do these in the order that the reloads were reported,
  2537.      since reloads of base and index registers precede reloads of operands
  2538.      and the operands may need the base and index registers reloaded.  */
  2539.  
  2540.   for (j = 0; j < n_reloads; j++)
  2541.     {
  2542.       register rtx old;
  2543.       rtx store_insn;
  2544.  
  2545.       old = reload_in[j];
  2546.       if (old != 0 && ! reload_inherited[j]
  2547.       && reload_reg_rtx[j] != old
  2548.       && reload_reg_rtx[j] != 0)
  2549.     {
  2550.       register rtx reloadreg = reload_reg_rtx[j];
  2551.       rtx oldequiv = 0;
  2552.       enum machine_mode mode;
  2553.       rtx where;
  2554.       rtx this_reload_insn = 0;
  2555.  
  2556. #if 0
  2557.       /* No longer done because these paradoxical subregs now occur
  2558.          only for regs and for spilled stack slots, and in either case
  2559.          we can safely reload in the nominal machine mode.  */
  2560.  
  2561.       /* Strip off of OLD any size-increasing SUBREGs such as
  2562.          (SUBREG:SI foo:QI 0).  */
  2563.  
  2564.       while (GET_CODE (old) == SUBREG && SUBREG_WORD (old) == 0
  2565.          && (GET_MODE_SIZE (GET_MODE (old))
  2566.              > GET_MODE_SIZE (GET_MODE (SUBREG_REG (old)))))
  2567.         old = SUBREG_REG (old);
  2568. #endif
  2569.  
  2570.       /* Determine the mode to reload in.
  2571.          This is very tricky because we have three to choose from.
  2572.          There is the mode the insn operand wants (reload_inmode[J]).
  2573.          There is the mode of the reload register RELOADREG.
  2574.          There is the intrinsic mode of the operand, which we could find
  2575.          by stripping some SUBREGs.
  2576.          It turns out that RELOADREG's mode is irrelevant:
  2577.          we can change that arbitrarily.
  2578.  
  2579.          Consider (SUBREG:SI foo:QI) as an operand that must be SImode;
  2580.          then the reload reg may not support QImode moves, so use SImode.
  2581.          If foo is in memory due to spilling a pseudo reg, this is safe,
  2582.          because the QImode value is in the least significant part of a
  2583.          slot big enough for a SImode.  If foo is some other sort of
  2584.          memory reference, then it is impossible to reload this case,
  2585.          so previous passes had better make sure this never happens.
  2586.  
  2587.          Then consider a one-word union which has SImode and one of its
  2588.          members is a float, being fetched as (SUBREG:SF union:SI).
  2589.          We must fetch that as SFmode because we could be loading into
  2590.          a float-only register.  In this case OLD's mode is correct.
  2591.  
  2592.          Consider an immediate integer: it has VOIDmode.  Here we need
  2593.          to get a mode from something else.
  2594.  
  2595.          In some cases, there is a fourth mode, the operand's
  2596.          containing mode.  If the insn specifies a containing mode for
  2597.          this operand, it overrides all others.
  2598.  
  2599.          I am not sure whether the algorithm here is always right,
  2600.          but it does the right things in those cases.  */
  2601.  
  2602.       mode = GET_MODE (old);
  2603.       if (mode == VOIDmode)
  2604.         mode = reload_inmode[j];
  2605.       if (reload_strict_low[j])
  2606.         mode = GET_MODE (SUBREG_REG (reload_in[j]));
  2607.  
  2608.       /* If reloading from memory, see if there is a register
  2609.          that already holds the same value.  If so, reload from there.
  2610.          We can pass 0 as the reload_reg_p argument because
  2611.          any other reload has either already been emitted,
  2612.          in which case find_equiv_reg will see the reload-insn,
  2613.          or has yet to be emitted, in which case it doesn't matter
  2614.          because we will use this equiv reg right away.  */
  2615.  
  2616.       if (GET_CODE (old) == MEM
  2617.           || (GET_CODE (old) == REG
  2618.           && REGNO (old) >= FIRST_PSEUDO_REGISTER
  2619.           && reg_renumber[REGNO (old)] < 0))
  2620.         oldequiv = find_equiv_reg (old, insn, GENERAL_REGS,
  2621.                        -1, 0, 0, mode);
  2622.  
  2623.       /* If OLDEQUIV is a spill register, don't use it for this
  2624.          if any other reload needs it at an earlier stage of this insn
  2625.          or at this stage.  */       
  2626.       if (oldequiv && GET_CODE (oldequiv) == REG
  2627.           && spill_reg_order[REGNO (oldequiv)] >= 0
  2628.           && (! reload_reg_free_p (REGNO (oldequiv), reload_when_needed[j])
  2629.           || ! reload_reg_free_before_p (REGNO (oldequiv),
  2630.                          reload_when_needed[j])))
  2631.         oldequiv = 0;
  2632.  
  2633.       /* If OLDEQUIV is not a spill register,
  2634.          don't use it if any other reload wants it.  */
  2635.       if (oldequiv && GET_CODE (oldequiv) == REG
  2636.           && spill_reg_order[REGNO (oldequiv)] < 0)
  2637.         {
  2638.           int k;
  2639.           for (k = 0; k < n_reloads; k++)
  2640.         if (reload_reg_rtx[k] != 0 && k != j
  2641.             && reg_overlap_mentioned_p (reload_reg_rtx[k], oldequiv))
  2642.           {
  2643.             oldequiv = 0;
  2644.             break;
  2645.           }
  2646.         }
  2647.  
  2648.       if (oldequiv == 0)
  2649.         oldequiv = old;
  2650.  
  2651.       /* Encapsulate both RELOADREG and OLDEQUIV into that mode,
  2652.          then load RELOADREG from OLDEQUIV.  */
  2653.  
  2654.       if (GET_MODE (reloadreg) != mode)
  2655.         reloadreg = gen_rtx (SUBREG, mode, reloadreg, 0);
  2656.       while (GET_CODE (oldequiv) == SUBREG && GET_MODE (oldequiv) != mode)
  2657.         oldequiv = SUBREG_REG (oldequiv);
  2658.       if (GET_MODE (oldequiv) != VOIDmode
  2659.           && mode != GET_MODE (oldequiv))
  2660.         oldequiv = gen_rtx (SUBREG, mode, oldequiv, 0);
  2661.  
  2662.       /* Decide where to put reload insn for this reload.  */
  2663.       switch (reload_when_needed[j])
  2664.         {
  2665.         case RELOAD_OTHER:
  2666.           where = first_operand_address_reload_insn;
  2667.           break;
  2668.         case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  2669.           where = first_other_reload_insn;
  2670.           break;
  2671.         case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  2672.           where = first_output_reload_insn;
  2673.           break;
  2674.         case RELOAD_FOR_OPERAND_ADDRESS:
  2675.           where = insn;
  2676.         }
  2677.  
  2678.       special = 0;
  2679.  
  2680.       /* Auto-increment addresses must be reloaded in a special way.  */
  2681.       if (GET_CODE (oldequiv) == POST_INC
  2682.           || GET_CODE (oldequiv) == POST_DEC
  2683.           || GET_CODE (oldequiv) == PRE_INC
  2684.           || GET_CODE (oldequiv) == PRE_DEC)
  2685.         {
  2686.           /* Prevent normal processing of this reload.  */
  2687.           special = 1;
  2688.           /* Output a special code sequence for this case.  */
  2689.           this_reload_insn
  2690.         = inc_for_reload (reloadreg, oldequiv, reload_inc[j], where);
  2691.         }
  2692.  
  2693.       /* If we are reloading a pseudo-register that was set by the previous
  2694.          insn, see if we can get rid of that pseudo-register entirely
  2695.          by redirecting the previous insn into our reload register.  */
  2696.  
  2697.       else if (optimize && GET_CODE (old) == REG
  2698.            && REGNO (old) >= FIRST_PSEUDO_REGISTER
  2699.            && dead_or_set_p (insn, old)
  2700.            /* This is unsafe if some other reload
  2701.               uses the same reg first.  */
  2702.            && (reload_when_needed[j] == RELOAD_OTHER
  2703.                || reload_when_needed[j] == RELOAD_FOR_INPUT_RELOAD_ADDRESS))
  2704.         {
  2705.           rtx temp = PREV_INSN (insn);
  2706.           while (temp && GET_CODE (temp) == NOTE)
  2707.         temp = PREV_INSN (temp);
  2708.           if (temp
  2709.           && GET_CODE (temp) == INSN
  2710.           && GET_CODE (PATTERN (temp)) == SET
  2711.           && SET_DEST (PATTERN (temp)) == old
  2712.           /* Make sure we can access insn_operand_constraint.  */
  2713.           && asm_noperands (PATTERN (temp)) < 0
  2714.           /* This is unsafe if prev insn rejects our reload reg.  */
  2715.           && constraint_accepts_reg_p (insn_operand_constraint[recog_memoized (temp)][0],
  2716.                            reloadreg)
  2717.           /* This is unsafe if operand occurs more than once in current
  2718.              insn.  Perhaps some occurrences aren't reloaded.  */
  2719.           && count_occurrences (PATTERN (insn), old) == 1
  2720.           /* Don't risk splitting a matching pair of operands.  */
  2721.           && ! reg_mentioned_p (old, SET_SRC (PATTERN (temp))))
  2722.         {
  2723.           /* Store into the reload register instead of the pseudo.  */
  2724.           SET_DEST (PATTERN (temp)) = reloadreg;
  2725.           /* If these are the only uses of the pseudo reg,
  2726.              pretend for GDB it lives in the reload reg we used.  */
  2727.           if (reg_n_deaths[REGNO (old)] == 1
  2728.               && reg_n_sets[REGNO (old)] == 1)
  2729.             {
  2730.               reg_renumber[REGNO (old)] = REGNO (reload_reg_rtx[j]);
  2731.               alter_reg (REGNO (old), -1);
  2732.             }
  2733.           special = 1;
  2734.         }
  2735.         }
  2736.  
  2737.       /* We can't do that, so output an insn to load RELOADREG.
  2738.          Keep them in the following order:
  2739.          all reloads for input reload addresses,
  2740.          all reloads for ordinary input operands,
  2741.          all reloads for addresses of non-reloaded operands,
  2742.          the insn being reloaded,
  2743.          all reloads for addresses of output reloads,
  2744.          the output reloads.  */
  2745.       if (! special)
  2746.         this_reload_insn = gen_input_reload (reloadreg, oldequiv, where);
  2747.  
  2748.       /* Update where to put other reload insns.  */
  2749.       if (this_reload_insn)
  2750.         switch (reload_when_needed[j])
  2751.           {
  2752.           case RELOAD_OTHER:
  2753.         if (first_other_reload_insn == first_operand_address_reload_insn)
  2754.           first_other_reload_insn = this_reload_insn;
  2755.         break;
  2756.           case RELOAD_FOR_OPERAND_ADDRESS:
  2757.         if (first_operand_address_reload_insn == insn)
  2758.           first_operand_address_reload_insn = this_reload_insn;
  2759.         if (first_other_reload_insn == insn)
  2760.           first_other_reload_insn = this_reload_insn;
  2761.           }
  2762.  
  2763.       /* reload_inc[j] was formerly processed here.  */
  2764.     }
  2765.  
  2766.       /* Add a note saying the input reload reg
  2767.      dies in this insn, if anyone cares.  */
  2768. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  2769.       if (old != 0
  2770.       && reload_reg_rtx[j] != old
  2771.       && reload_reg_rtx[j] != 0
  2772.       && reload_out[j] == 0
  2773.       && PRESERVE_DEATH_INFO_REGNO_P (REGNO (reload_reg_rtx[j])))
  2774.     {
  2775.       register rtx reloadreg = reload_reg_rtx[j];
  2776.  
  2777.       /* The code below is incorrect except for RELOAD_OTHER.  */
  2778.       if (reload_when_needed[j] != RELOAD_OTHER)
  2779.         abort ();
  2780.  
  2781.       /* Add a death note to this insn, for an input reload.  */
  2782.  
  2783.       if (! dead_or_set_p (insn, reloadreg))
  2784.         REG_NOTES (insn)
  2785.           = gen_rtx (EXPR_LIST, REG_DEAD,
  2786.              reloadreg, REG_NOTES (insn));
  2787.     }
  2788. #endif
  2789.  
  2790.       /* ??? The following code is inadequate.
  2791.      It handles regs inherited via reg_last_reloaded_contents
  2792.      but not those inherited via find_equiv_reg.
  2793.      Note that we can't expect spill_reg_store to contain anything
  2794.      useful in the case of find_equiv_reg.  */
  2795.  
  2796. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  2797.       /* For some registers it is important to keep the REG_DEATH
  2798.      notes accurate for the final pass.
  2799.      If we are inheriting an old output-reload out of such a reg,
  2800.      the reg no longer dies there, so remove the death note.  */
  2801.  
  2802.       if (reload_reg_rtx[j] != 0
  2803.       && PRESERVE_DEATH_INFO_REGNO_P (REGNO (reload_reg_rtx[j]))
  2804.       && reload_inherited[j] && reload_spill_index[j] >= 0
  2805.       && GET_CODE (reload_in[j]) == REG
  2806.       && spill_reg_store[reload_spill_index[j]] != 0
  2807.       && regno_dead_p (REGNO (reload_reg_rtx[j]),
  2808.                spill_reg_store[reload_spill_index[j]]))
  2809.     {
  2810.       remove_death (REGNO (reload_reg_rtx[j]),
  2811.             spill_reg_store[reload_spill_index[j]]);
  2812.     }
  2813. #endif
  2814.  
  2815.       /* If we are reloading a register that was recently stored in with an
  2816.      output-reload, see if we can prove there was
  2817.      actually no need to store the old value in it.  */
  2818.  
  2819.       if (optimize && reload_inherited[j] && reload_spill_index[j] >= 0
  2820.       /* This is unsafe if some other reload uses the same reg first.  */
  2821.       && (reload_when_needed[j] == RELOAD_OTHER
  2822.           || reload_when_needed[j] == RELOAD_FOR_INPUT_RELOAD_ADDRESS)
  2823.       && GET_CODE (reload_in[j]) == REG
  2824.       && REGNO (reload_in[j]) >= FIRST_PSEUDO_REGISTER
  2825.       && spill_reg_store[reload_spill_index[j]] != 0
  2826.       && dead_or_set_p (insn, reload_in[j])
  2827.       /* This is unsafe if operand occurs more than once in current
  2828.          insn.  Perhaps some occurrences weren't reloaded.  */
  2829.       && count_occurrences (PATTERN (insn), reload_in[j]) == 1)
  2830.     delete_output_reload (insn, j, reload_spill_index[j]);
  2831.  
  2832.       /* Input-reloading is done.  Now do output-reloading,
  2833.      storing the value from the reload-register after the main insn
  2834.      if reload_out[j] is nonzero.  */
  2835.       old = reload_out[j];
  2836.       if (old != 0
  2837.       && reload_reg_rtx[j] != old
  2838.       && reload_reg_rtx[j] != 0
  2839.       /* An output operand that dies right away
  2840.          does need a reload reg, but need not
  2841.          be copied from it.  */
  2842.       && ! (GET_CODE (old) == REG
  2843.         && find_reg_note (insn, REG_DEAD, old)))
  2844.     {
  2845.       register rtx reloadreg = reload_reg_rtx[j];
  2846.       enum machine_mode mode;
  2847.  
  2848. #if 0
  2849.       /* Strip off of OLD any size-increasing SUBREGs such as
  2850.          (SUBREG:SI foo:QI 0).  */
  2851.  
  2852.       while (GET_CODE (old) == SUBREG && SUBREG_WORD (old) == 0
  2853.          && (GET_MODE_SIZE (GET_MODE (old))
  2854.              > GET_MODE_SIZE (GET_MODE (SUBREG_REG (old)))))
  2855.         old = SUBREG_REG (old);
  2856. #endif
  2857.  
  2858.       /* Determine the mode to reload in.
  2859.          See comments above (for input reloading).  */
  2860.  
  2861.       mode = GET_MODE (old);
  2862.       if (mode == VOIDmode)
  2863.         abort ();        /* Should never happen for an output.  */
  2864. #if 0
  2865.         mode = reload_inmode[j];
  2866. #endif
  2867.       if (reload_strict_low[j])
  2868.         mode = GET_MODE (SUBREG_REG (reload_out[j]));
  2869.  
  2870.       /* Encapsulate both RELOADREG and OLD into that mode,
  2871.          then load RELOADREG from OLD.  */
  2872.       if (GET_MODE (reloadreg) != mode)
  2873.         reloadreg = gen_rtx (SUBREG, mode, reloadreg, 0);
  2874.       /* If OLD is a subreg, then strip it, since the subreg will
  2875.          be altered by this very reload (if it's a strict_low_part).  */
  2876.       while (GET_CODE (old) == SUBREG && GET_MODE (old) != mode)
  2877.         old = SUBREG_REG (old);
  2878.       if (GET_MODE (old) != VOIDmode
  2879.           && mode != GET_MODE (old))
  2880.         old = gen_rtx (SUBREG, mode, old, 0);
  2881.       /* Output the reload insn.  */
  2882.       store_insn = emit_insn_before (gen_move_insn (old, reloadreg),
  2883.                      first_output_reload_insn);
  2884.       first_output_reload_insn = store_insn;
  2885.       /* If this output reload doesn't come from a spill reg,
  2886.          clear any memory of reloaded copies of the pseudo reg.
  2887.          If this output reload comes from a spill reg,
  2888.          reg_has_output_reload will make this do nothing.  */
  2889.       note_stores (PATTERN (store_insn), forget_old_reloads_1);
  2890.  
  2891. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  2892.       /* If final will look at death notes for this reg,
  2893.          put one on the output-reload insn.  */
  2894.       if (PRESERVE_DEATH_INFO_REGNO_P (REGNO (reloadreg)))
  2895.         REG_NOTES (store_insn)
  2896.         = gen_rtx (EXPR_LIST, REG_DEAD,
  2897.                reloadreg, REG_NOTES (store_insn));
  2898.  
  2899.       /* Move all death-notes from the insn being reloaded
  2900.          to the output reload, if they are for things used
  2901.          as inputs in this output reload.  */
  2902.       if (GET_CODE (old) != REG)
  2903.         {
  2904.           /* The note we will examine next.  */
  2905.           rtx reg_notes = REG_NOTES (insn);
  2906.           /* The place that pointed to this note.  */
  2907.           rtx *prev_reg_note = ®_NOTES (insn);
  2908.  
  2909.           while (reg_notes)
  2910.         {
  2911.           rtx next_reg_notes = XEXP (reg_notes, 1);
  2912.           if (REG_NOTE_KIND (reg_notes) == REG_DEAD
  2913.               && reg_mentioned_p (XEXP (reg_notes, 0), old))
  2914.             {
  2915.               *prev_reg_note = next_reg_notes;
  2916.               XEXP (reg_notes, 1) = REG_NOTES (store_insn);
  2917.               REG_NOTES (store_insn) = reg_notes;
  2918.             }
  2919.           else
  2920.             prev_reg_note = &XEXP (reg_notes, 1);
  2921.  
  2922.           reg_notes = next_reg_notes;
  2923.         }
  2924.         }
  2925. #endif
  2926.     }
  2927.       else store_insn = 0;
  2928.  
  2929.       if (reload_spill_index[j] >= 0)
  2930.     spill_reg_store[reload_spill_index[j]] = store_insn;
  2931.     }
  2932.  
  2933.   /* Move death notes from INSN to output-operand-address reload insns.  */
  2934. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  2935.   {
  2936.     rtx insn1;
  2937.     /* Loop over those insns, last ones first.  */
  2938.     for (insn1 = PREV_INSN (first_output_reload_insn); insn1 != insn;
  2939.      insn1 = PREV_INSN (insn1))
  2940.       if (GET_CODE (insn1) == INSN && GET_CODE (PATTERN (insn1)) == SET)
  2941.     {
  2942.       rtx source = SET_SRC (PATTERN (insn1));
  2943.  
  2944.       /* The note we will examine next.  */
  2945.       rtx reg_notes = REG_NOTES (insn);
  2946.       /* The place that pointed to this note.  */
  2947.       rtx *prev_reg_note = ®_NOTES (insn);
  2948.  
  2949.       /* If the note is for something used in the source of this
  2950.          output address reload insn, move the note.  */
  2951.       while (reg_notes)
  2952.         {
  2953.           rtx next_reg_notes = XEXP (reg_notes, 1);
  2954.           if (REG_NOTE_KIND (reg_notes) == REG_DEAD
  2955.           && reg_mentioned_p (XEXP (reg_notes, 0), source))
  2956.         {
  2957.           *prev_reg_note = next_reg_notes;
  2958.           XEXP (reg_notes, 1) = REG_NOTES (insn1);
  2959.           REG_NOTES (insn1) = reg_notes;
  2960.         }
  2961.           else
  2962.         prev_reg_note = &XEXP (reg_notes, 1);
  2963.  
  2964.           reg_notes = next_reg_notes;
  2965.         }
  2966.     }
  2967.   }
  2968. #endif
  2969. }
  2970.  
  2971. /* Emit code before BEFORE_INSN to perform an input reload of IN to RELOADREG.
  2972.    Handle case of reloading a PLUS expression (currently only happens for
  2973.    stack slots with out-of-range offset).
  2974.  
  2975.    Returns last insn emitted.  */
  2976.  
  2977. static rtx
  2978. gen_input_reload (reloadreg, in, before_insn)
  2979.      rtx reloadreg;
  2980.      rtx in;
  2981.      rtx before_insn;
  2982. {
  2983. #if 0  /* Install this in version 1.37.  Avoid risk for now.  */
  2984.   if (GET_CODE (in) == PLUS)
  2985.     {
  2986.       /* Don't use gen_move_insn to make what is actually an add insn.  */
  2987.       emit_insn_before (gen_move_insn (reloadreg, XEXP (in, 0)), before_insn);
  2988.       emit_insn_before (gen_add2_insn (reloadreg, XEXP (in, 1)), before_insn);
  2989.     }
  2990.   else
  2991. #endif
  2992.     emit_insn_before (gen_move_insn (reloadreg, in), before_insn);
  2993.  
  2994.   return PREV_INSN (before_insn);
  2995. }
  2996.  
  2997. /* Delete a previously made output-reload
  2998.    whose result we now believe is not needed.
  2999.    First we double-check.
  3000.  
  3001.    INSN is the insn now being processed.
  3002.    J is the reload-number for this insn,
  3003.    and SPILL_INDEX is the index in spill_regs of the reload-reg
  3004.    being used for the reload.  */
  3005.  
  3006. static void
  3007. delete_output_reload (insn, j, spill_index)
  3008.      rtx insn;
  3009.      int j;
  3010.      int spill_index;
  3011. {
  3012.   register rtx i1;
  3013.  
  3014.   /* Get the raw pseudo-register referred to.  */
  3015.  
  3016.   rtx reg = reload_in[j];
  3017.   while (GET_CODE (reg) == SUBREG)
  3018.     reg = SUBREG_REG (reg);
  3019.  
  3020.   /* If the pseudo-reg we are reloading is no longer referenced
  3021.      anywhere between the store into it and here,
  3022.      and no jumps or labels intervene, then the value can get
  3023.      here through the reload reg alone.
  3024.      Otherwise, give up--return.  */
  3025.   for (i1 = NEXT_INSN (spill_reg_store[spill_index]);
  3026.        i1 != insn; i1 = NEXT_INSN (i1))
  3027.     {
  3028.       if (GET_CODE (i1) == CODE_LABEL || GET_CODE (i1) == JUMP_INSN)
  3029.     return;
  3030.       if ((GET_CODE (i1) == INSN || GET_CODE (i1) == CALL_INSN)
  3031.       && reg_mentioned_p (reg, PATTERN (i1)))
  3032.     return;
  3033.     }
  3034.  
  3035.   /* If this insn will store in the pseudo again,
  3036.      the previous store can be removed.  */
  3037.   if (reload_out[j] == reload_in[j])
  3038.     delete_insn (spill_reg_store[spill_index]);
  3039.  
  3040.   /* See if the pseudo reg has been completely replaced
  3041.      with reload regs.  If so, delete the store insn
  3042.      and forget we had a stack slot for the pseudo.  */
  3043.   else if (reg_n_deaths[REGNO (reg)] == 1
  3044.        && reg_basic_block[REGNO (reg)] >= 0
  3045.        && find_regno_note (insn, REG_DEAD, REGNO (reg)))
  3046.     {
  3047.       rtx i2;
  3048.  
  3049.       /* We know that it was used only between here
  3050.      and the beginning of the current basic block.
  3051.      (We also know that the last use before INSN was
  3052.      the output reload we are thinking of deleting, but never mind that.)
  3053.      Search that range; see if any ref remains.  */
  3054.       for (i2 = PREV_INSN (insn); i2; i2 = PREV_INSN (i2))
  3055.     {
  3056.       /* Uses which just store in the pseudo don't count,
  3057.          since if they are the only uses, they are dead.  */
  3058.       if (GET_CODE (i2) == INSN
  3059.           && GET_CODE (PATTERN (i2)) == SET
  3060.           && SET_DEST (PATTERN (i2)) == reg)
  3061.         continue;
  3062.       if (GET_CODE (i2) == CODE_LABEL
  3063.           || GET_CODE (i2) == JUMP_INSN)
  3064.         break;
  3065.       if ((GET_CODE (i2) == INSN || GET_CODE (i2) == CALL_INSN)
  3066.           && reg_mentioned_p (reg, PATTERN (i2)))
  3067.         /* Some other ref remains;
  3068.            we can't do anything.  */
  3069.         return;
  3070.     }
  3071.  
  3072.       /* Delete the now-dead stores into this pseudo.  */
  3073.       for (i2 = PREV_INSN (insn); i2; i2 = PREV_INSN (i2))
  3074.     {
  3075.       /* Uses which just store in the pseudo don't count,
  3076.          since if they are the only uses, they are dead.  */
  3077.       if (GET_CODE (i2) == INSN
  3078.           && GET_CODE (PATTERN (i2)) == SET
  3079.           && SET_DEST (PATTERN (i2)) == reg)
  3080.         delete_insn (i2);
  3081.       if (GET_CODE (i2) == CODE_LABEL
  3082.           || GET_CODE (i2) == JUMP_INSN)
  3083.         break;
  3084.     }
  3085.  
  3086.       /* For the debugging info,
  3087.      say the pseudo lives in this reload reg.  */
  3088.       reg_renumber[REGNO (reg)] = REGNO (reload_reg_rtx[j]);
  3089.       alter_reg (REGNO (reg), -1);
  3090.     }
  3091. }
  3092.  
  3093.  
  3094. /* Output reload-insns to reload VALUE into RELOADREG. 
  3095.    VALUE is a autoincrement or autodecrement RTX whose operand
  3096.    is a register or memory location;
  3097.    so reloading involves incrementing that location.
  3098.  
  3099.    INC_AMOUNT is the number to increment or decrement by (always positive).
  3100.    This cannot be deduced from VALUE.
  3101.  
  3102.    INSN is the insn before which the new insns should be emitted.
  3103.  
  3104.    The return value is the first of the insns emitted.  */
  3105.  
  3106. static rtx
  3107. inc_for_reload (reloadreg, value, inc_amount, insn)
  3108.      rtx reloadreg;
  3109.      rtx value;
  3110.      int inc_amount;
  3111.      rtx insn;
  3112. {
  3113.   /* REG or MEM to be copied and incremented.  */
  3114.   rtx incloc = XEXP (value, 0);
  3115.   /* Nonzero if increment after copying.  */
  3116.   int post = (GET_CODE (value) == POST_DEC || GET_CODE (value) == POST_INC);
  3117.  
  3118.   /* No hard register is equivalent to this register after
  3119.      inc/dec operation.  If REG_LAST_RELOAD_REG were non-zero,
  3120.      we could inc/dec that register as well (maybe even using it for
  3121.      the source), but I'm not sure it's worth worrying about.  */
  3122.   if (GET_CODE (incloc) == REG)
  3123.     reg_last_reload_reg[REGNO (incloc)] = 0;
  3124.  
  3125.   if (GET_CODE (value) == PRE_DEC || GET_CODE (value) == POST_DEC)
  3126.     inc_amount = - inc_amount;
  3127.  
  3128.   /* First handle preincrement, which is simpler.  */
  3129.   if (! post)
  3130.     {
  3131.       /* If incrementing a register, assume we can
  3132.      output an insn to increment it directly.  */
  3133.       if (GET_CODE (incloc) == REG &&
  3134.       (REGNO (incloc) < FIRST_PSEUDO_REGISTER
  3135.        || reg_renumber[REGNO (incloc)] >= 0))
  3136.     {
  3137.       rtx first_new
  3138.         = emit_insn_before (gen_add2_insn (incloc,
  3139.                            gen_rtx (CONST_INT, VOIDmode,
  3140.                             inc_amount)),
  3141.                 insn);
  3142.       emit_insn_before (gen_move_insn (reloadreg, incloc), insn);
  3143.       return first_new;
  3144.     }
  3145.       else
  3146.     /* Else we must not assume we can increment the location directly
  3147.        (even though on many target machines we can);
  3148.        copy it to the reload register, increment there, then save back.  */
  3149.     {
  3150.       rtx first_new
  3151.         = emit_insn_before (gen_move_insn (reloadreg, incloc), insn);
  3152.       emit_insn_before (gen_add2_insn (reloadreg,
  3153.                        gen_rtx (CONST_INT, VOIDmode,
  3154.                             inc_amount)),
  3155.                 insn);
  3156.       emit_insn_before (gen_move_insn (incloc, reloadreg), insn);
  3157.       return first_new;
  3158.     }
  3159.     }
  3160.   /* Postincrement.
  3161.      Because this might be a jump insn or a compare, and because RELOADREG
  3162.      may not be available after the insn in an input reload,
  3163.      we must do the incrementation before the insn being reloaded for.  */
  3164.   else
  3165.     {
  3166.       /* Copy the value, then increment it.  */
  3167.       rtx first_new
  3168.     = emit_insn_before (gen_move_insn (reloadreg, incloc), insn);
  3169.  
  3170.       /* If incrementing a register, assume we can
  3171.      output an insn to increment it directly.  */
  3172.       if (GET_CODE (incloc) == REG &&
  3173.       (REGNO (incloc) < FIRST_PSEUDO_REGISTER
  3174.        || reg_renumber[REGNO (incloc)] >= 0))
  3175.     {
  3176.       emit_insn_before (gen_add2_insn (incloc,
  3177.                        gen_rtx (CONST_INT, VOIDmode,
  3178.                             inc_amount)),
  3179.                 insn);
  3180.     }
  3181.       else
  3182.     /* Else we must not assume we can increment INCLOC
  3183.        (even though on many target machines we can);
  3184.        increment the copy in the reload register,
  3185.        save that back, then decrement the reload register
  3186.        so it has the original value.  */
  3187.     {
  3188.       emit_insn_before (gen_add2_insn (reloadreg,
  3189.                        gen_rtx (CONST_INT, VOIDmode,
  3190.                             inc_amount)),
  3191.                 insn);
  3192.       emit_insn_before (gen_move_insn (incloc, reloadreg), insn);
  3193.       emit_insn_before (gen_sub2_insn (reloadreg,
  3194.                        gen_rtx (CONST_INT, VOIDmode,
  3195.                             inc_amount)),
  3196.                 insn);
  3197.     }
  3198.       return first_new;
  3199.     }
  3200. }
  3201.  
  3202. /* Return 1 if we are certain that the constraint-string STRING allows
  3203.    the hard register REG.  Return 0 if we can't be sure of this.  */
  3204.  
  3205. static int
  3206. constraint_accepts_reg_p (string, reg)
  3207.      char *string;
  3208.      rtx reg;
  3209. {
  3210.   int value = 0;
  3211.   int regno = true_regnum (reg);
  3212.  
  3213.   /* We win if this register is a general register
  3214.      and each alternative accepts all general registers.  */
  3215.   if (! TEST_HARD_REG_BIT (reg_class_contents[(int) GENERAL_REGS], regno))
  3216.     return 0;
  3217.  
  3218.   /* Initialize for first alternative.  */
  3219.   value = 0;
  3220.   /* Check that each alternative contains `g' or `r'.  */
  3221.   while (1)
  3222.     switch (*string++)
  3223.       {
  3224.       case 0:
  3225.     /* If an alternative lacks `g' or `r', we lose.  */
  3226.     return value;
  3227.       case ',':
  3228.     /* If an alternative lacks `g' or `r', we lose.  */
  3229.     if (value == 0)
  3230.       return 0;
  3231.     /* Initialize for next alternative.  */
  3232.     value = 0;
  3233.     break;
  3234.       case 'g':
  3235.       case 'r':
  3236.     value = 1;
  3237.       }
  3238. }
  3239.  
  3240. /* Return the number of places FIND appears within X.  */
  3241.  
  3242. static int
  3243. count_occurrences (x, find)
  3244.      register rtx x, find;
  3245. {
  3246.   register int i, j;
  3247.   register enum rtx_code code;
  3248.   register char *format_ptr;
  3249.   int count;
  3250.  
  3251.   if (x == find)
  3252.     return 1;
  3253.   if (x == 0)
  3254.     return 0;
  3255.  
  3256.   code = GET_CODE (x);
  3257.  
  3258.   switch (code)
  3259.     {
  3260.     case REG:
  3261.     case QUEUED:
  3262.     case CONST_INT:
  3263.     case CONST_DOUBLE:
  3264.     case SYMBOL_REF:
  3265.     case CODE_LABEL:
  3266.     case PC:
  3267.     case CC0:
  3268.       return 0;
  3269.     }
  3270.  
  3271.   format_ptr = GET_RTX_FORMAT (code);
  3272.   count = 0;
  3273.  
  3274.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  3275.     {
  3276.       switch (*format_ptr++)
  3277.     {
  3278.     case 'e':
  3279.       count += count_occurrences (XEXP (x, i), find);
  3280.       break;
  3281.  
  3282.     case 'E':
  3283.       if (XVEC (x, i) != NULL)
  3284.         {
  3285.           for (j = 0; j < XVECLEN (x, i); j++)
  3286.         count += count_occurrences (XVECEXP (x, i, j), find);
  3287.         }
  3288.       break;
  3289.     }
  3290.     }
  3291.   return count;
  3292. }
  3293.